Primary Arithmetic

// Primary Arithmetic.cpp : Defines the entry point for the console application. // #include "stdafx.h" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { char Data[20]={'/0'}; while(cin.getline(Data,20)) { if(Data[0]=='0'&&Data[1]==' '&&Data[2]=='0')break; else { bool flag=false; int addspace=0; int signbefore=0; int signend=0; int num=0; while(Data[num]!='/0') { if(Data[num]==' ')signbefore=num; ++num; } signend=num; int x,y; for(x=signbefore-1,y=signend-1;x>=0,y>signbefore;--x,--y) { int result=0; if((x==(signbefore-1))&&(y==(signend-1))) { result=(Data[x]-48)+(Data[y]-48); if(result>9) { flag=true; ++addspace; } else flag=false; } else if(((signend-signbefore-1)>signbefore)&&(x==0)&&(y==(signend-signbefore-1))) { int tmpend=signend-signbefore-1; while(tmpend>signbefore) { if(flag==true) { result=(Data[y]-48)+1; if(result>9) { flag=true; ++addspace; } else flag=false; } --tmpend; } break; } else if(((signend-1-signbefore)<signbefore)&&(x==(2*signbefore-signend))&&(y==(signbefore+1))) { int tmpbefore=2*signbefore-signend; while(tmpbefore>=0) { if(flag==true) { result=(Data[x]-48)+1; if(result>9) { flag=true; ++addspace; } else flag=false; } } break; } else { if(flag==true) { result=(Data[x]-48)+(Data[y]-48)+1; if(result>9) { flag=true; ++addspace; } else flag=false; } else { result=(Data[x]-48)+(Data[y]-48); if(result>9) { flag=true; ++addspace; } else flag=false; } } } if(addspace==0)cout<<"No carry operation."<<"/n"; else cout<<addspace<<" carry operation."<<"/n"; } } return 0; }  

你可能感兴趣的:(Primary Arithmetic)