输入输出处理
读取n行数据,每行数据不知多少个
#include<iostream>
#include<sstream>
using namespace std;
const int N = 1100;
int a[N];
int n;
int main(){
string line;
int cnt;
cin >> cnt;
getline(cin,line);//读掉回车
while(cnt -- )//重点
{
getline(cin,line);
stringstream ssin(line);
while(ssin >> a[n])n++;
}
for(int i = 0; i < n; i ++ )
{
cout<<a[i]<<" ";
}
return 0;
}
处理时间
//固定格式的输入处理
//时间进制转换
//输出格式整齐(补零)
#include<iostream>
#include<unordered_map>
using namespace std;
int n;
string line;
void get_time()
{
int h1,m1,h2,m2;
string t;
int sum1 = 0,sum2 = 0;
getline(cin,t);
sscanf(t.c_str(),"%d:%d",&h1,&m1);
getline(cin,t);
sscanf(t.c_str(),"%d:%d",&h2,&m2);
sum1 = h1*3600+m1*60;
sum2 = h2*3600+m2*60;
if(sum1<sum2) sum1+=86400;
int sum = sum1 - sum2;
int h,m;
h = sum/3600;
m = sum%3600 / 60;
printf("%02d:%02d\n",h,m);
}
int main()
{
scanf("%d",&n);
getline(cin,line);
while(n--)
{
get_time();
}
return 0;
}
字符串
数论
同模定理
(a+b)/m = 整数,则a恒等号b(mod m)