题目描述
给定一个整数,请将该数各个位上数字反转得到一个新数。新数也应满足整数的常见形式,即除非给定的原数为零,否则反转后得到的新数的最高位数字不应为零(参见样例2)。
输入输出格式
输入格式:
一个整数 NN
输出格式:
一个整数,表示反转后的新数。
输入输出样例
说明
数据范围
-1,000,000,000≤N≤1,000,000,000−1,000,000,000≤N≤1,000,000,000。
noip2011普及组第一题
。第41行代码由于之前忘记加‘ ’所以错惹。
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==' ') 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 }