a little gain
- I have trouble reading English question
- I don’t konw enough about the usual functions in C plus
- and today, I want to take some notes about the following question:
using some skills to translate int to string:
string int2string(int num){
stringstream s;
s<<sum;
return s.str();
}
the complete code:
#include<stdio.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b);
int c = a+b;
int flag = c<0?1:0;
c = c<0?-c:c;
if(flag)printf("-");
int mem[5];
int cnt=0;
while(c>999)
{
int tmp = c%1000;
c=c/1000;
mem[cnt++]=tmp;
// printf("%d %d\n",cnt-1,mem[cnt-1]);
}
mem[cnt++]=c;
for(int i=cnt-1;i>=0;i--)
{
if(i==cnt-1)
printf("%d",mem[i]);
else
printf("%03d",mem[i]);
if(i!=0)
printf(",");
}
return 0;
}
It had passed the oj: