1 条题解
-
0
C :
#include<stdio.h> #include<stdlib.h> int main() { int a,b,c,d; int m,n; for(a=1;a<=9;a++) for(b=0;b<=9;b++) for(c=0;c<=9;c++) for(d=0;d<=9;d++) { m=1000*a+100*b+10*c+d; n=1000*d+100*c+10*b+a; if(9*m==n) printf("%d%d%d%d\n",a,b,c,d); } //system("pause"); return 0; }
C++ :
#include<iostream> using namespace std; int main() { for(int i=1000; i<=9999; i++) { int a,b,c,d; a=i/1000; b=i/100-a*10; c=(i/10)%10; d=i%10; if(9*i==d*1000+c*100+b*10+a) cout<<i<<endl; } return 0; }
Java :
public class Main { public static void main(String[] args) { for (int i = 1000; i <= 1111; i++) { if(i*9==f(i)){ System.out.println(i) ; } } } public static int f(int n){ int k = 0 ; int i = 3 ; int t = 0 ; while(n>0){ t = n%10 ; for (int j = 0; j <i; j++) { t = t*10 ; } i-- ; k = k+t ; n = n/10 ; } return k; } }
- 1
信息
- ID
- 1152
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者