Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
help!help!help!where-ie-the-errer?# include <iostream.h> int i=0; int main() { int group; cin>>group; cin.get(); while(1) { int answer=0; int num[11]; int length=0; char* word=new char [30]; cin.getline(word,21); for(int j=0;j<21;j++) { int a=(int)word[j]; if(word[j]!=' '&&a>47) { num[length]=(int)word[j]-48; length++; } } if(length%2!=0) { if(num[0]==0) { switch (length) { case 3: answer=num[1]*10; answer-=num[2]; break; case 5: answer=num[1]*100+num[2]; answer-=num[4]*10+num[3]; break; case 7: answer=num[1]*1000+num[2]*10+num[3]; answer-=num[6]*100+num[5]*10+num[4]; break; case 9: answer=num[1]*10000+num[2]*100+num[3]*10+num[4]; answer-=num[8]*1000+num[7]*100+num[6]*10+num[5]; break; } } else { switch (length) { case 3: answer=num[0]*10+num[1]; answer-=num[2]; break; case 5: answer=num[0]*100+num[1]*10+num[2]; answer-=num[4]*10+num[3]; break; case 7: answer=num[0]*1000+num[1]*100+num[2]*10+num[3]; answer-=num[6]*100+num[5]*10+num[4]; break; case 9: answer=num[0]*10000+num[1]*1000+num[2]*100+num[3]*10+num[4]; answer-=num[8]*1000+num[7]*100+num[6]*10+num[5]; break; } } } else if(length%2==0) { int line=10; int point[10]; int number=0; if(num[0]!=0) { for(int k=1;k<length;k++) { if(num[k]-num[k-1]<line) { number=1; point[0]=k-1; line=num[k]-num[k-1]; } else if(num[k]-num[k-1]==line) { point[number]=k-1; number++; } } } else if(num[0]==0) { for(int k=2;k<length;k++) { if(num[k]-num[k-1]<line) { number=1; point[0]=k-1; line=num[k]-num[k-1]; } else if(num[k]-num[k-1]==line) { point[number]=k-1; number++; } } if(length==2) { answer=num[1]-num[0]; } } for(int u=0;u<number;u++) { int answer3=0; switch (length/2) { case 1: answer3=num[point[u]+1]-num[point[u]]; break; case 2: answer3=(num[point[u]+1]-num[point[u]])*10; break; case 3: answer3=(num[point[u]+1]-num[point[u]])*100; break; case 4: answer3=(num[point[u]+1]-num[point[u]])*1000; break; case 5: answer3=(num[point[u]+1]-num[point[u]])*10000; break; } int jj=length/2-1; int vv=0; for(int v=0;v<jj;v++) { if(v!=point[u]&&v!=point[u]+1) { int min=1; for(int w=length/2-2;w>vv;w--) { min*=10; } vv++; answer3+=num[v]*min; } else if(v==point[u]) { jj+=2; } } int kk=length/2; int tt=0; for(int s=length-1;s>kk;s--) { if(s!=point[u]&&s!=point[u]+1) { int max=1; for(int t=length/2-2;t>tt;t--) { max*=10; } tt++; answer3-=num[s]*max; } else if(s==point[u]+1) { kk-=2; } } if(answer==0) { answer=answer3; } else if(answer3<answer) { answer=answer3; } } } delete [] word; i++; cout<<answer<<endl; if(i==group) { break; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator