PAT程序设计考题——甲级1001( A+B Format ) C++实现

来源:互联网 发布:淘宝虚拟对话生成器 编辑:程序博客网 时间:2024/06/06 03:48

TO pat

#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<vector>
using namespace std;
int main(){
 int a,b;
 cin>>a>>b;
 int c=a+b;
 int temp=abs(c);
 if(abs(c)<1000) { cout<<c;
 return 0;
 }
 if(c<0) cout<<"-";
 int store[100101],num=0;
 while(temp>0)
 {
    store[num++]=temp%1000;
 temp=temp/1000; 
 }
 cout<<store[num-1];
 for(int i=num-2;i>=0;i--)
 printf(",%03d",store[i]);
 return 0;
 
}


阅读全文
0 0
原创粉丝点击