标签:style blog http color os io for 2014
#include<iostream> #include<cmath> using namespace std; int main(){ long a,b,c; int i,flag; bool is_positive; char result[9]; while(cin>>a>>b) { c = a+b; if( c>0 ) is_positive = true; else is_positive = false; flag = 0; if(abs(c) >= 1000){ c = abs(c); //取绝对值 for( i=0; c>0; i++){ result[i] = c%10 + ‘0‘; //数字转换成字符 c = c/10; if(flag == 2 && c != 0 ) { i++; result[i] = ‘,‘; //每三个加一个逗号 flag = 0; } else flag++; } if( !is_positive ) //结果为负数时 { result[i] = ‘-‘; cout<<result[i]; } i--; //i指向第一个数字 for(; i>=0; i--){ cout<<result[i]; } cout<<endl; } else { cout<<c<<endl; } } return 0; }
标签:style blog http color os io for 2014
原文地址:http://www.cnblogs.com/michaeljunlove/p/3879656.html