1 条题解
-
0
C :
#include<stdio.h> void main(){ int n,t,x,c=0; scanf("%d",&n); while(1==1){ t=n; x=0; while(t!=0){ x=x*10+t%10; t=t/10; } if(n==x){ break; }else{ n=n+x; c++; } } printf("%d",c); }C++ :
#include<iostream> using namespace std; int main(){ int n,i,j,t,d,m; cin>>n; for(i=1;;i++){ d=n; m=0; for(j=1;;j++){ if(n==0){ break; } t=n%10; m=m*10+t; n=n/10; } if(m==d){ cout<<i-1; break; }else{ n=d+m; } } }Pascal :
var a,tot:int64; s:string; function PLD(s:string):boolean; var i,n:longint; begin n:=length(s); for i:=1 to n div 2 do if s[i]<>s[n+1-i] then exit(false); exit(true); end; function REV(a:int64):int64; begin REV:=0; while(a>0)do begin REV:=REV*10+a mod 10; a:=a div 10; end; end; begin readln(a); tot:=0; while(true)do begin //writeln(a); str(a,s); if PLD(s) then begin writeln(tot); break; end; a:=a+REV(a); inc(tot); end; end.Java :
import java.util.Scanner; public class Main{ static int n=0; public static void main(String[] args) { int number=new Scanner(System.in).nextInt(); dohws(number); System.out.println(n); } public static void dohws(int a){ if(a==gethws(a)){ n=n; }else{ a=a+gethws(a); n++; dohws(a); } } public static Integer gethws(int a){ String a_s=String.valueOf(a); int count=a_s.length(); String s=""; for(int i=1;i<=count;i++){ int m=(int) Math.pow(10, i); int n=(int) Math.pow(10, i-1); s+=a%m/n; } return Integer.valueOf(s); } }Python :
n = int(input()) t = 0 while(n != int(str(n)[::-1])): n += int(str(n)[::-1]) t += 1 print(t)
- 1
信息
- ID
- 81
- 时间
- 1000ms
- 内存
- 64MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者