1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include<iostream> using namespace std; int main(){ string num,numcopy[3]; int switchnum=1,isdot=0,isslash=0,ispercent=0; cin>>num; if(num=="0"){ cout<<"0"<<endl; return 0; } for(int i=0;i<num.size();i++){ if(num[i]=='/'){ isslash=1; switchnum=2; continue; } if(num[i]=='.'){ isdot=1; switchnum=2; continue; } if(num[i]=='%'){ ispercent=1; break; } numcopy[switchnum]+=num[i]; } if(numcopy[1]=="0"&&(numcopy[2]=="0"||numcopy[2]=="")){ cout<<"0"; if(isdot) cout<<"."; if(isslash) cout<<"/"; if(ispercent){ cout<<"%"<<endl; return 0; } cout<<"0"<<endl; return 0; } int nozero=0; if(numcopy[1]=="0"){ cout<<"0"; }else for(int i=numcopy[1].size()-1;i>=0;i--){ if(numcopy[1][i]=='0'&&nozero==0){ continue; }else if(numcopy[1][i]!='0'){ nozero=1; } cout<<numcopy[1][i]; } if(isdot){ cout<<"."; if(numcopy[2]=="0"){ cout<<"0"<<endl; return 0; } nozero=0; for(int i=0;i<numcopy[2].size();i++){ if(numcopy[2][i]=='0'&&nozero==0){ nozero=0; numcopy[2][i]='\0'; }else if(numcopy[2][i]!='0'){ nozero=1; } } for(int i=numcopy[2].size()-1;i>=0;i--){ cout<<numcopy[2][i]; } cout<<endl; } if(isslash){ cout<<"/"; if(numcopy[2]=="0"){ cout<<"0"<<endl; return 0; } nozero=0; for(int i=numcopy[2].size()-1;i>=0;i--){ if(numcopy[2][i]=='0'&&nozero==0){ continue; }else if(numcopy[2][i]!='0'){ nozero=1; } cout<<numcopy[2][i]; } cout<<endl; } if(ispercent){ cout<<"%"<<endl; } return 0; }
|