1 条题解

  • 0
    @ 2021-6-14 22:56:32

    C :

    #include<stdio.h>
    int main(){
      printf("1089\n");
      return 0;
    }
    

    C++ :

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    
    int main()
    {
    	int i;
    	char a[5],b[6];
    	for(i=1000;i<=9999;i++)
    	{
    		sprintf(a,"%d",i);
    		sprintf(b,"%d",i*9);
    		reverse(b,b+strlen(b));
    		if(!strcmp(a,b))
    			printf("%d\n",i);
    	}
    	return 0;
    }
    

    Pascal :

    var
     n,a,b,c,d,s:longint;
    begin
     for n:=1000 to 9999 do
     begin
      a:=n div 1000;
      b:=n mod 1000 div 100;
      c:=n mod 100 div 10;
      d:=n mod 10;
      s:=d*1000+c*100+b*10+a;
      if s div 9=n then writeln(n);
     end;
    end.
    

    Java :

    
    
    public class Main {
    	public static void main(String[] args) {
    		for (int i = 1000; i < 1111; i++) {
                 if(f(i)==i*9){
                	 System.out.println(i);
                 }
    		}
    		
    	}
    
    	private static int f(int n) {
    		int a[] = new int[4];
    		int i = 3;
    		while (n > 0) {
    			a[i] = n % 10;
    			n = n / 10;
    			i-- ;
    		}
    		
    		
    		int s = 0 ;
    		
    		for (int j = 0; j < a.length; j++) {
    			s = (int) (s + a[j]*Math.pow(10, j)) ;
    		}
    		
    		return s ;
    	}
    }
    
    
    • 1

    信息

    ID
    51
    时间
    1000ms
    内存
    32MiB
    难度
    9
    标签
    递交数
    11
    已通过
    5
    上传者