PAT 甲级1001 A+B Format
文章目录
我的代码:
#include<iostream>
using namespace std;
int main(){
int a,b; cin>>a>>b;
string s= to_string(a+b);
int length = s.length();
for (int i = 0; i < length ; ++i) {
cout<<s[i];
if(s[0] != '-'){
if( (length-1-i)%3==0 && i != length-1)
cout<<',';
}
else{
if((length-1-i)%3==0 && i!= length-1 && i!=0)
cout<<',';
}
}
}
主要考察对下标的观察。
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论