1 solutions
-
0
C :
#include<stdio.h> int main(){ int a; while(scanf("%d",&a)!=EOF){ int t,p,i; for(i=a+1;i>a;i++){ p=i; int b=i; t=0; while(b!=0){ t=t*10+b%10; b=b/10; } if(t==p){ printf("%d\n",p); break; } } } return 0; }
C++ :
#include <iostream> using namespace std; bool isHuiWen(int n) { int sum = 0; int m = n; while (n !=0) { sum = sum * 10 + n%10; n = n /10; } return sum == m; } int main() { int X; cin>>X; int n = X+1; while(isHuiWen(n) == false) n++; cout<<n<<endl; return 0; }
Java :
public class Main { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in) ; while (input.hasNextInt()) { String str = input.nextLine(); int a = str.length(); int number1 = 0; int number2 = 0; int b =a-1; for (int i=0;i<a;i++) { char c =str.charAt(i); int d = c-48; number1 += d*Math.pow(10.0,b); b--; } int d = a-1; for(int i = 0;i<a;i++) { number2 += 9*Math.pow(10,d); d--; } if(number1==number2) { int e = (int)Math.pow(10,a)*1 +1; System.out.println(e); } else { if (a % 2 != 0){ int n = 0,m=0; int o = 0; for(int j=0;j<a/2;j++){ n += (str.charAt(j)-48)*Math.pow(10,o); o++; } int l = a/2-1; for(int j = a/2+1;j<a;j++) { m +=(str.charAt(j) - 48)*Math.pow(10,l); l--; } int number3 = 0; b =a-1; for(int i = 0;i<=a/2;i++) { number3+=(str.charAt(i)-48)*Math.pow(10,b); b--; } int k = 0; for(int i= 0;i<a/2;i++){ number3+=(str.charAt(i)-48)*Math.pow(10,k); k++; } if(n>m) { System.out.println(number3); } else{ number3=number3+(int)Math.pow(10,a/2); System.out.println(number3); } } if(a%2==0) { int n = 0,m=0; int o = 0; for(int j=0;j<a/2;j++){ n += (str.charAt(j)-48)*Math.pow(10,o); o++; } int l = a/2-1; for(int j = a/2;j<a;j++) { m +=(str.charAt(j) - 48)*Math.pow(10,l); l--; } int number3 = 0; b =a-1; for(int i = 0;i<a/2;i++) { number3+=(str.charAt(i)-48)*Math.pow(10,b); b--; } int k = 0; for(int i= 0;i<a/2;i++){ number3+=(str.charAt(i)-48)*Math.pow(10,k); k++; } if(n>m) { System.out.println(number3); } else{ int v = a/2; for(int f = 0;f<=1;f++){ number3+=1*Math.pow(10,v); v--; } System.out.println(number3); } } } } } }
- 1
Information
- ID
- 10036
- Time
- 1000ms
- Memory
- 64MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By