萌新25分求助!!

P1553 数字反转(升级版)

还是快读好 ```cpp #include<bits/stdc++.h> #define fre(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout); #define heap priority_queue using namespace std; typedef long long ll; const int N = 1e4 + 10; const int INF = 0x3f3f3f3f; int main() { double x = 0; char c = getchar(); while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } if(c == '.') { c = getchar(); double i = 10; while(c >= '0' && c <= '9') { x = x + (c - '0') / i ; i *= 10; c = getchar(); } if(c == '%') { x /= 100; } } else if(c == '%') { x /= 100; } else if(c == '/') { double y = 0; c = getchar(); while(c >= '0' && c <= '9') { y = y * 10 + c - '0'; c = getchar(); } x /= y; } cout << x; return 0; } ```
by aaron0919 @ 2023-07-09 19:31:39


建议用快读, 否则容易卡时长
by aaron0919 @ 2023-07-09 19:32:34


我的 $50$ 来行代码如数奉上: ```cpp #include<bits/stdc++.h> using namespace std; int type(string x){ for(int i=0;i<x.length();i++){ if(x[i]=='.')return 0; else if(x[i]=='/')return 1; else if(x[i]=='%')return 2; } return 3; } int finds(string x,char y){ int position=0; for(;x[position]!=y;position++); return position; } string number(string x){ reverse(x.begin(),x.end()); if(x=="0")return x; string j; int empty=0;bool t=1; for(;empty<x.length();empty++){ if(x[empty]!='0' || t==0){ t=0;j+=x[empty]; } else if(x[empty]=='0' && t==1){} } return j; } string lastnumber(string x){ reverse(x.begin(),x.end()); if(x=="0")return x; string j; int empty=x.length()-1;bool t=1; for(;empty>=0;empty--){ if(x[empty]!='0' || t==0){ t=0;j+=x[empty]; } else if(x[empty]=='0' && t==1){} } return j; } int main(void){ string s; cin>>s; int y=type(s); if(y==0){ string k,l; int w=finds(s,'.'); for(int i=0;i<w;i++){ k+=s[i]; } for(int i=w+1;i<s.length();i++){ l+=s[i]; } k=number(k);l=lastnumber(l); reverse(l.begin(),l.end()); cout<<k<<"."<<l; } else if(y==3){ cout<<number(s); } else if(y==2){ string a; for(int i=0;i<s.length()-1;i++){ a+=s[i]; } cout<<number(a)<<"%"; } else{ string k,l; int w=finds(s,'/'); for(int i=0;i<w;i++){ k+=s[i]; } for(int i=w+1;i<s.length();i++){ l+=s[i]; } k=number(k);l=number(l); cout<<k<<"/"<<l; } return 0; } ```
by __Ending__ @ 2023-07-09 19:43:20


去前导零和后导零错了。
by __Ending__ @ 2023-07-09 19:58:29


|