九度 1064-反序数[数学] | Acm之家
设N是一个四位数,它的9倍恰好是其反序数(例如:1234的反序数是4321)
超过1111的话,就成5位数了。- 剪纸
X. http://blog.csdn.net/sjf0115/article/details/8495578
Read full article from 九度 1064-反序数[数学] | Acm之家
设N是一个四位数,它的9倍恰好是其反序数(例如:1234的反序数是4321)
超过1111的话,就成5位数了。- 剪纸
for ( int i=1001;i<=1111;i++) |
5 | if (9*i==i%10*1000+i/10%10*100+i/100%10*10+i/1000%10) |
6 | printf ( "%d\n" ,i); |
X. http://blog.csdn.net/sjf0115/article/details/8495578
- for(i = 1000;i < 10000;i++)
- {
- n = i;
- m = 0;
- //求反序数
- while(n)
- {
- m=m*10+n%10;
- n=n/10;
- }
- if(m==i*9)
- {
- printf("%d\n",i);
- }
- }
for (n = 1000; n <= 9999; n ++) |
11 | { |
12 | n9 = n * 9; |
13 | rev = reverse_number(n); |
14 | if (n9 == rev) |
15 | { |
16 | printf ( "%d\n" ,n); |
17 | } |
18 | } |
26 | int reverse_number( int a) |
27 | { |
28 | int rev[5]; |
29 | int i, j, b, d; |
30 |
31 | for (i = 0; a ; i ++) |
32 | { |
33 | rev[i] = a % 10; |
34 | a /= 10; |
35 | } |
36 |
37 | for (j = i - 1, b = 0, d = 1; j >= 0; j --) |
38 | { |
39 | b += rev[j] * d; |
40 | d *= 10; |
41 | } |
42 |
43 | return b; |
44 | } |