Reflection --P1307 digit reversal

Title Description

Given an integer, the number of the digital please obtained by inverting each bit of a new number. The new number should also meet common form of integers that, unless given the original number is zero, otherwise obtained by inverting the highest digit of the new number should not be zero (see sample 2).

Input and output formats

Input formats:

 

An integer  N N

 

Output formats:

 

An integer that represents the number of new reversal after.

 

Sample input and output

Input Sample # 1:  Copy
123
Output Sample # 1:  Copy
321
Input Sample # 2:  Copy
-380
Output Sample # 2:  Copy
-83

Explanation

data range

-1,000,000,000≤N≤1,000,000,0001,000,000,000N1,000,000,000。

noip2011 universal set of first title

. Since the line 41 prior to forget to add '' so wrong mess.

 

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cmath>
 4 #include <stdio.h>
 5 #include <cstring>
 6 #include <string>
 7 #include <cstdlib>
 8 #include <queue>
 9 #include <stack>
10 #include <set>
11 #include <vector>
12 #include <map>
13 #include <list>
14 #define maxn 1000000007
15 //#include <>
16 using namespace std;
17 
18 int main()
19 {
20     stack<char > s;
21     char ch;
22     int flag=0;
23     while(ch=getchar())
24     {
25         if(ch=='\n')
26             break;
27         if(ch=='-'&&flag==0)
28                 flag=1;
29             else{
30             //    cout<<"push"<<ch<<endl;
31                 s.push(ch);
32             }            
33     }        
34     if(flag==1)
35         cout<<"-";
36         
37     flag=0;
38     //cout<<s.top()<<endl;
39     while(!s.empty())
40     {
41         if(s.top()=='0'&&flag==0)
42         {
43             //cout<<"zero pop"<<s.top()<<endl;
44             s.pop();
45             
46             continue;    
47         }
48         flag=1;
49     //    cout<<"pop"<<s.top()<<endl;
50         cout<<s.top();
51         s.pop();
52     }
53     
54     cout<<endl;
55     return 0;
56 }

 

Guess you like

Origin www.cnblogs.com/greenaway07/p/10969456.html