人见人爱a+b
#include<stdio.h>
int main()
{
int n,i,j,a1,a2,a3,b1,b2,b3,c1=0,c2=0,c3=0;//c1记录小时,c2记录分钟,c3记录秒;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d%d%d%d%d%d",&a1,&a2,&a3,&b1,&b2,&b3);
c3=a3+b3;
if(c3>=60)
{
c3=c3-60;
c2++;//分钟+1;
}
c2=c2+a2+b2;
if(c2>=60)
{
c2=c2-60;
c1++;//小时+1;
}
c1=c1+a1+b1;
printf("%d %d %d\n",c1,c2,c3);
c1=0;
c2=0;
c3=0;
}
return 0;
}
一、A+B*C
#include <stdio.h>
int main()
{
int a, b,c,n;
scanf("%d %d %d",&a,&b,&c);
n=a+b*c;
if(n<0)
{
printf("-");//输出“-”号
n=-n;//取其绝对值
}
if(n<1000) printf("%d\n",n );
else if(n<1000000) printf("%d,%03d\n",n/1000,n%1000 );
else printf("%d,%03d,%03d\n",n/1000000,n%1000000/1000,n%1000 );//判断n的范围,用0补充位数
return 0;
}
二、A+B/C
#include<stdio.h>
int main()
{
int a,b,c,intn=0,intp=0;
double dout=0,doum=0;
scanf("%d%d%d",&a,&b,&c);
intn=a+b*1.0/c;//n is int; mistake: b*1.0/c;
dout=a+b*1.0/c;//t is double; mistake: b*1.0/c;
doum=dout-intn;//doum : decimal
intp=doum*100;//intp : (int)decimal*100
if(intp<0)intp=-intp;// |intp|;
if(intn<0)
{
printf("-");
intn=-intn;
}
if(intn<1000) printf("%d",intn );
else if(intn<1000000) printf("%d,%03d",intn/1000,intn%1000 );
else printf("%d,%03d,%03d",intn/1000000,intn%1000000/1000,intn%1000 );
printf(".%02d",intp);//print the part of decimal
return 0;
}
//-10 1 3
//-10 1 4
//-1000000 1 3
//1000000 1 4
//-1000 9 1
遇到的问题:
2016/2/26