本文主要是介绍ural 1123,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
找大于等于原数的最小回文数字 代码比较烂...........
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>using namespace std;
char s[2010];
int main()
{scanf("%s",s);int len = strlen(s);int l = 0, r = len - 1;int flag = 0;int T = 0;while(r>=l){if(r - l > 1){if(s[l] < s[r])flag = 1;s[r] = s[l];}else if(r - l == 1){if(s[r] > s[l])s[l] = s[r];else if(s[l] > s[r]){s[r] = s[l];}else{if(flag){if(s[r] != '9'){s[r] += 1;s[l] += 1;}elsewhile(1){if(s[r] == '9'){s[r] = '0';s[l] = '0';r++;l--;}else{s[r] += 1;s[l] += 1;T = 1;break;}}}}}else{if(flag){if(s[r] != '9')s[r] += 1;elsewhile(1){if(s[r] == '9'){s[r] = '0';s[l] = '0';r--;l++;}else{s[r] += 1;s[l] += 1;break;}}}}if(T)break;l++;r--;}puts(s);return 0;
}
这篇关于ural 1123的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!