https://www.luogu.org/problemnew/show/P1553
忘记给整数加上前导零去除的代码了.
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- char s[40];
- int main(){
- scanf("%s",s);
- int n=strlen(s);
- for(int i=0;i<n;i++){
- if(s[i]=='.'){
- reverse(s,s+i);
- reverse(s+i+1,s+n);
- int haveout=0;
- for(int j=0;j<i;j++){
- if(s[j]=='0'&&haveout==0)
- ;
- else{
- printf("%c",s[j]);
- haveout=1;
- }
- }
- if(haveout==0){
- printf("0");
- }
- printf(".");
- int allzero=1;
- int last=0;
- for(int j=i+1;j<n;j++){
- if(s[j]!='0'){
- last=j;
- allzero=0;
- }
- }
- if(allzero){
- printf("0\n");
- }
- else{
- for(int j=i+1;j<=last;j++){
- printf("%c",s[j]);
- }
- printf("\n");
- }
- return 0;
- }
- else if(s[i]=='/'){
- reverse(s,s+i);
- reverse(s+i+1,s+n);
- int haveout=0;
- for(int j=0;j<i;j++){
- if(s[j]=='0'&&haveout==0)
- ;
- else{
- printf("%c",s[j]);
- haveout=1;
- }
- }
- if(haveout==0){
- printf("0");
- }
- printf("/");
- haveout=0;
- for(int j=i+1;j<n;j++){
- if(s[j]=='0'&&haveout==0)
- ;
- else{
- printf("%c",s[j]);
- haveout=1;
- }
- }
- if(haveout==0){
- printf("0");
- }
- printf("\n");
- return 0;
- }
- else if(s[i]=='%'){
- reverse(s,s+i);
- int haveout=0;
- for(int j=0;j<i;j++){
- if(s[j]=='0'&&haveout==0)
- ;
- else{
- printf("%c",s[j]);
- haveout=1;
- }
- }
- if(haveout==0){
- printf("0");
- }
- printf("\%\n");
- return 0;
- }
- }
- reverse(s,s+n);
- int haveout=0;
- for(int j=0;j<n;j++){
- if(s[j]=='0'&&haveout==0)
- ;
- else{
- printf("%c",s[j]);
- haveout=1;
- }
- }
- if(haveout==0){
- printf("0");
- }
- printf("\n");
- }
来源: http://www.bubuko.com/infodetail-2927259.html