RE了三个点,都是和0有关的。 代码如下:
//RE*3:NO.12 && NO.15 && NO.20
#include<iostream>
#include<stack>
#include<queue>
#include<string>
#define elif else if
using namespace std;
int main(){
string str;
cin>>str;
if(str[0]=='0' && str.size()==1){
cout<<0;
return 0;
}
if(str.find(".")!=-1)/*是小数*/{
int before_float=str.find(".")-1;
deque<char>q;
stack<char>s;
bool flag=false;
if(str.find("0")==0)cout<<'0';
else{
for(int i=0;i<before_float+1;i++)s.push(str[i]);
if(s.top()=='0')flag=true;
while(flag){
if(s.top()=='0')s.pop();
else flag=false;
}
while(!s.empty()){
cout<<s.top();
s.pop();
}
}
cout<<'.';
if(before_float+2==str.size()-1){
cout<<'0';
return 0;
}
for(int i=before_float+2;i<str.size();i++)q.push_back(str[i]);
flag=false;
if(q.back()=='0')flag=true;
while(flag){
if(q.back()=='0')q.pop_back();
else flag=false;
}
if(q.front()=='0')flag=true;
while(flag){
if(q.front()=='0')q.pop_front();
else flag=false;
}
while(!q.empty()){
cout<<q.back();
q.pop_back();
}
}//小数finish
elif(str.find("%")!=-1)/*是百分数*/{
stack<char>s;
for(int i=0;i<str.size()-1;i++)s.push(str[i]);
bool flag=false;
if(s.top()=='0')flag=true;
while(flag){
if(s.top()=='0')s.pop();
else flag=false;
}
while(!s.empty()){
cout<<s.top();
s.pop();
}
cout<<'%';
}//百分数finish
elif(str.find("/")!=-1)/*是分数*/{
int before_slash=str.find("/")-1;
deque<char>q;
stack<char>s;
for(int i=0;i<before_slash+1;i++)s.push(str[i]);
bool flag=false;
if(s.top()=='0')flag=true;
while(flag){
if(s.top()=='0')s.pop();
else flag=false;
}
while(!s.empty()){
cout<<s.top();
s.pop();
}
cout<<'/';
for(int i=before_slash+2;i<str.size();i++)q.push_back(str[i]);
flag=false;
if(q.back()=='0')flag=true;
while(flag){
if(q.back()=='0')q.pop_back();
else flag=false;
}
if(q.front()=='0')flag=true;
while(flag){
if(q.front()=='0')q.pop_front();
else flag=false;
}
while(!q.empty()){
cout<<q.back();
q.pop_back();
}
}
else/*是整数*/{
stack<char>s;
for(int i=0;i<str.size();i++)s.push(str[i]);
bool flag=false;
if(s.top()=='0')flag=true;
while(flag){
if(s.top()=='0')s.pop();
else flag=false;
}
while(!s.empty()){
cout<<s.top();
s.pop();
}
}//整数finish
return 0;
}
方法麻烦了请不要介意