pat甲级1023
1 #include <cstring> 2 #include <iostream> 3 #include <algorithm> 4 using namespace std; 5 int book[10]; 6 char num[22], result[22]; 7 int main() 8 { 9 10 scanf("%s", num); 11 int len = strlen(num); 12 int flag = 0; 13 for (int i = len-1; i >= 0; i--) 14 { 15 int temp =( num[i]-'0') * 2; 16 result[i] = flag + temp % 10+'0'; 17 flag = 0; 18 if (temp >=10) flag = 1; 19 } 20 result[len] = '\0'; 21 if (flag == 1) 22 { 23 cout << "No" << endl; 24 cout << 1 << result; 25 } 26 else 27 { 28 string temp(result); 29 sort(num, num + len); 30 sort(result, result + len); 31 if (strcmp(result, num) == 0) 32 cout << "Yes" << endl; 33 else cout << "No" << endl; 34 cout << temp.c_str(); 35 } 36 return 0; 37 }
这道题比较简单 注意全局变量默认赋初值0或者NULL

浙公网安备 33010602011771号