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 |
为什么,WA,请高手帮助啊#include<iostream> #include<cstring> using namespace std; int main() {char digit[32]; char temp,min; int i,t,j,len; bool flag; while(scanf("%s",digit) && digit[0]!='.') { flag = true; len= strlen(digit); if( digit[len-1] == '2' ) { digit[len-1] = '5'; flag = false; } else if ( digit[len-1] == '6' ){ digit[len-1] = '9'; flag=false; } else { digit[len-2] = digit[len-1]; t = len-2; i=t-1; while(i>=0 && digit[i] >= digit[i+1] && digit[i] != '2' && digit[i] !='6' ) { i--; } if(i<0) flag = true; else if ( digit[i]<digit[i+1]) {if (digit[i]== '2'&& digit[i+1]>'5') { digit[i] = '5'; flag=false; } else {flag=false; min=i+1; for( j= i+1 ; j<= len-2 ; j++ ) if(digit[j]>digit[i] &&digit[min]> digit[j] ) min = j; if( digit[min] == '9' && digit[i] <'6') digit[min] = '6'; if( digit[min] == '5' && digit[i] <'2' ) digit[min]= '2'; temp=digit[min]; digit[min] = digit[i]; digit[i] = temp; } } else if (digit[i] == '2' ) {digit[i] = '5'; flag=false; } else if (digit[i] == '6') {digit[i] = '9'; flag=false;} for ( j = i+1 ;j<=len -2; j++ ) if ( digit[j] == '5' ) digit[j] = '2'; else if ( digit[j] == '9' ) digit[j]= '6'; for(i = i+1 ;i < len-2 ; i++ ) for( j = i+1 ; j<= len-2 ; j++ ) if( digit[i] > digit[j] ) { temp = digit[i]; digit[i]= digit[j]; digit[j] = temp; } digit[len-1] = digit[len-2]; digit[len-2] = '.'; } if (flag ) cout<<"The price cannot be raised."<<endl; else cout<< digit <<endl; len=strlen(digit); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator