zoukankan      html  css  js  c++  java
  • 杭电1266 Reverse Number

    Reverse Number

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 3771    Accepted Submission(s): 1736


    Problem Description
    Welcome to 2006'4 computer college programming contest!

    Specially, I give my best regards to all freshmen! You are the future of HDU ACM! And now, I must tell you that ACM problems are always not so easy, but, except this one... Ha-Ha!

    Give you an integer; your task is to output its reverse number. Here, reverse number is defined as follows:
    1. The reverse number of a positive integer ending without 0 is general reverse, for example, reverse (12) = 21;
    2. The reverse number of a negative integer is negative, for example, reverse (-12) = -21;
    3. The reverse number of an integer ending with 0 is described as example, reverse (1200) = 2100.
     
    Input
    Input file contains multiple test cases. There is a positive integer n (n<100) in the first line, which means the number of test cases, and then n 32-bit integers follow.
     
    Output
    For each test case, you should output its reverse number, one case per line.
     
    Sample Input
    3 12 -12 1200
     
    Sample Output
    21 -21 2100
     
    Author
    lcy
     
    Source
     
    Recommend
    lxj
     
    如题中描述,这是一道简单题!但开始做的时候考虑的不够周全,遗漏了0出现在整数非末端的情况,导致一次WA!改进后AC,代码如下:
    View Code
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 
     4 int reverse( int x )
     5 {
     6     int cnt  = 0;
     7     if( x < 0 )
     8     {
     9         printf( "-" );
    10         x = -x;
    11     }
    12     else if( x == 0 )
    13     {    
    14          printf( "%d\n",x );
    15          return 0;
    16     }
    17     while( x % 10 == 0 )
    18     {
    19            x = x / 10;
    20            cnt++;
    21     }
    22     while( x != 0 )
    23     {
    24            printf( "%d", x % 10 );
    25            x = x / 10;
    26     }
    27     while( cnt-- )
    28            printf( "%d", 0 );
    29     printf( "\n" );
    30     return 0;
    31 }
    32 
    33 int main(int argc, char *argv[])
    34 {
    35     int n, a;
    36     scanf( "%d", &n );
    37     while( n-- )
    38     {
    39            scanf( "%d", &a );
    40            reverse(a);      
    41     }
    42   
    43 //  system("PAUSE");    
    44   return 0;
    45 }
  • 相关阅读:
    Kafka: Producer (0.10.0.0)
    Kafka:架构简介【转】
    ZooKeeper示例 分布式锁
    机器学习---人脸对齐的基于形状模型的训练
    人脸妆容迁移---研究和思考
    机器学习----人脸对齐的算法-ASM.AAM..CLM.SDM
    基于opencv+Dlib的面部合成(Face Morph)
    c语言编程-----指向二维数组的指针
    工具软件 PYUV打开raw图片
    eclipse 使用问题
  • 原文地址:https://www.cnblogs.com/yizhanhaha/p/3058703.html
Copyright © 2011-2022 走看看