zoukankan      html  css  js  c++  java
  • HDU1266--Reverse Number

    Reverse Number
    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 4022 Accepted Submission(s): 1877


    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
    HDU 2006-4 Programming Contest


    Recommend
    lxj

     1 #include<cstdio> 
     2 #include<cstring> 
     3 #include<algorithm> 
     4 #include<iostream> 
     5 using namespace std; 
     6     
     7 char str[1000]; 
     8     
     9 int main() 
    10 { 
    11     int n; 
    12     scanf("%d",&n); 
    13     getchar(); 
    14     while(n--) 
    15     { 
    16         memset(str,0,sizeof(str)); 
    17         scanf("%s",str); 
    18         int len=strlen(str),i; 
    19         int flag=0; 
    20         int num=0; 
    21         int sign=0; 
    22         for(i=len-1;i>=0;i--) 
    23         { 
    24             if(str[0]>'9'||str[0]<'0'&&flag==0) 
    25             { 
    26                 flag=1; 
    27                 printf("%c",str[0]); 
    28             } 
    29             if(flag==1&&i==0)continue; 
    30             if(str[i]=='0'&&sign==0) 
    31             { 
    32                 num++; 
    33                 continue; 
    34             } 
    35             if(str[i]>='0'&&str[i]<='9') 
    36             { 
    37                 sign=1; 
    38                 printf("%c",str[i]); 
    39             } 
    40         } 
    41         for(i=0;i<num;i++) 
    42             printf("0"); 
    43         printf("
    "); 
    44     } 
    45     return 0; 
    46 }
    View Code
  • 相关阅读:
    Linux九阴真经之催心掌残卷5(正则表达式)
    Linux九阴真经之催心掌残卷4(grep文本处理 )
    Linux九阴真经之催心掌残卷3
    Linux九阴真经之催心掌残卷2
    0.1.kubeadm快速部署kubernetes
    0.2.kubeadm搭建kubernetes高可用集群(CentOS)
    Nginx——模块(1)
    Nginx——主配置段
    Nginx——安装
    Nginx——I/O模型
  • 原文地址:https://www.cnblogs.com/zafuacm/p/3185234.html
Copyright © 2011-2022 走看看