码迷,mamicode.com
首页 > 编程语言 > 详细

武汉科技大学ACM :1003: 零起点学算法14——三位数反转

时间:2014-12-09 22:52:57      阅读:385      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   color   sp   strong   on   数据   

Problem Description

水题

Input

输入1个3位数(题目包含多组测试数据)

Output

分离该3位数的百位、十位和个位,反转后输出(每组测试数据一行)

Sample Input

250

Sample Output

052

HINT

分离出各位数字可以用取余和除数

注意在C语言里,2个整数相乘除结果还是整数 比如8/3在C语言里结果是2

取余采用符号%

比如8%3的结果应该是2即8除以3后的余数

 1 #include <stdio.h>
 2 
 3 int main()
 4 
 5 {
 6 
 7          int splitInt,one,ten,hundred;
 8 
 9         
10 
11          while(scanf("%d",&splitInt)!=EOF)
12 
13          {                
14 
15                    hundred = splitInt/100;
16 
17                    ten = splitInt%100/10;             
18 
19                    one = splitInt%10;            
20 
21                   printf("%d%d%d\n",one,ten,hundred);           
22 
23          }       
24 
25          return 0;
26 
27 }

其他代码:

 1 #include<stdio.h>
 2 int main()
 3 {
 4     int n,m;
 5     while(scanf("%d",&n)!=EOF)
 6     {
 7         while(n>0)
 8         {
 9             m=n%10;
10             n/=10;
11             printf("%d",m);
12         }
13         printf("\n");
14     }
15     return 0;
16 }

 

武汉科技大学ACM :1003: 零起点学算法14——三位数反转

标签:des   style   blog   io   color   sp   strong   on   数据   

原文地址:http://www.cnblogs.com/liuwt365/p/4154132.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!