GDUFE ACM-1127

题目:http://acm.gdufe.edu.cn/Problem/read/id/1127

 

国庆作业系列——D.反序输出正整数

Time Limit: 2000/1000ms (Java/Others)

Problem Description:

输入任意一个正整数,将其各位数字反序输出(例如输入123,输出321)

Input:

测试数据有多组。每组是1个正整数n,0<n<21亿,n不会以0结尾,也不以0开头

Output:

输出结果

Sample Input:

1432
123
132

Sample Output:

2341
321
231

思路:我是用字符串从后往前打印,《算法竞赛入门经典》有用除法和余数的方法

难度:非常简单

代码:
 1 #include<stdio.h>
 2 int main()
 3 {
 4     int i,j;
 5     char ch[10];
 6     while(scanf("%s",ch)!=EOF)
 7     {
 8         i=0;
 9         while(ch[i]!='\0')
10             i=i+1;
11     for(j=i-1;j>=0;j--)
12         printf("%c",ch[j]);
13         printf("\n");
14     }
15     return 0;
16 }

 

posted @ 2016-10-17 20:47  ruoruoruoruo  阅读(138)  评论(0编辑  收藏  举报