第二天考试前,来写一下今天刷题的题解吧,希望今天题不难,早AK早去看比赛(你怎么天天有比赛看,就不能学学人家fyx、ljh、rh)......
咳咳,言归正传,一道水题,有人想用字符串来做,you can you up,这确实是一个好方法,嗯嗯,对,但是我想用模拟,暴力为王!!!
其实也就一个地方要注意,我注释的代码,最开始的思路是每三位存在一个位置上,然后倒着输出,简单的想好像没有问题,但是如果碰到三位都是0,就死了(14分,pta还是很友好的),既然这样,每个数字存一个位置好啦,然后倒着输出,啥时候该输出逗号判断一下,over
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
int c,cnt;
int ans[105];
int main()
{
int a,b;
cin >> a >> b;
c=a+b;
if(c<0)
{
printf("-");
}
c=abs(c);
/*int ccc=c;
int cc=0;
/*while(ccc)
{
ccc/=10;
cc++;
}
/*if(cc%3>0)
{
int llo=1;
for(int i = 1;i <= cc%3;i++)
{
llo*=10;
}
ans[++cnt]=c%llo;
c/=llo;
}
while(c)
{
ans[++cnt]=c%1000;
c/=1000;
}
for(int i = cnt;i > 1;i--)
{
cout << ans[i] <<",";
}*/
while(c)
{
ans[++cnt]=c%10;
c/=10;
}
for(int i = cnt;i > 1;i--)
{
printf("%d",ans[i]);
if(i>0&&(i-1)%3==0) printf(",");
}
cout << ans[1];
return 0 ;
}