一. 题目大意:给出两个整数 按照美式写法输出两个数之和(每隔三位补充一个逗号)。
二. 易错点:注意0的时候,需要特判。
三. 不认识的单词(本英语渣渣的专属板块)
commas 逗号
The digits must be separated into groups of three by commas。
每隔三位必须以一个逗号相分隔。
四. 题外话:好久没写C++程序了,都忘记freopen函数怎么用了,另外这次做题ban了debug,(根据考过的学长说考场上的IDE比较傲娇,很有可能不能使用debug来处理程序)采用cout的方式单步输出来判断程序的运行。所以写的很繁琐。
五. 完整代码
#include <cstdio>
#include <algorithm>
#include <string>
#include <iostream>
#include <cstring>
using namespace std;
string reserve(string str,int i){
string st;
int j=0;
for(i=i-1;i>=0;i--){
//cout<<i<<endl;
cout<<str[i];
st[j++]=str[i];
//cout<<st<<endl;
}
return st;
}
int main(){
string str;
str.resize(20);
int a,b;
scanf("%d %d",&a,&b);
a=a+b;
//printf("%d\n",a);
if(a<0) printf("-");
a=abs(a);
int i=0,j=0;
if(a==0) {printf("0"); return 0;}
while(a!=0){
str[i++]=a%10+'0';
j++;a=a/10;
if(j%3==0&&a!=0) str[i++]=',';
//cout<<a<<endl;
}
/*for(int i=0;i<20;i++){
printf("%c\n",str[i]);
}*/
string st;
st=reserve(str,i);
cout<<st;
return 0;
}