求助大佬
查看原帖
求助大佬
82817
Leonard7楼主2020/9/14 23:23
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

string a, b;

int main(){
	int t; 
	int temp = 0, tt, js = 0;
	cin >> a;
	int l = a.size();
	for(int i = 0; i <= l - 1; i++){
		if(a[i] == '.'){
		 t = 2;
		 tt = i;
		 break;
	}	
	else if(a[i] == '/'){
		t = 3;
		tt = i;
		break;
	}
	else if(a[i] == '%'){
		t = 4;
	}
	else t = 1;
}
	if(t == 1){
		for(int i = l - 1; i >= 0; i--){
		if(a[i] == '0' && temp == 0 && i != 0) continue;
		if(a[i] != '0' || (a[i] == '0' && temp == 1) || (i == 0 && a[i] == '0')){
			temp = 1;
			printf("%c", a[i]);
			} 
		}
	}
	if(t == 2){
		if(tt == 1){
			printf("%c", a[0]);
		}
		else{
			for(int i = tt - 1; i >= 0; i--){
			if(a[i] == '0' && temp == 0) continue;
		if(a[i] != '0' || (a[i] == '0' && temp == 1)){
			temp = 1;
			printf("%c", a[i]);
			}
		}
		}
		printf(".");
		temp = 0;
			for(int i = tt + 1; i <= l - 1; i++){
			if(a[i] == '0' && temp == 0) continue;
		if(a[i] != '0' || (a[i] == '0' && temp == 1)){
			temp = 1;
			b += a[i];
			js++;
			}
		}
		for(int j = js - 1; j >= 0; j--){
			printf("%c", b[j]);
		}
		if(b == "") printf("0");
	}
	if(t == 3){
		if(tt == 1){
			printf("%c", a[0]);
		}
		else {
			for(int i = tt - 1; i >= 0; i--){
			if(a[i] == '0' && temp == 0) continue;
		if(a[i] != '0' || (a[i] == '0' && temp == 1)){
			temp = 1;
			printf("%c", a[i]);
			}
		}
		}
		printf("/");
		temp = 0;
		if(l - tt == 2){
			printf("%c", a[tt + 1]);
		}
		else{
			for(int i = tt + 1; i <= l - 1; i++){
			if(a[i] == '0' && temp == 0) continue;
		if(a[i] != '0' || (a[i] == '0' && temp == 1)){
			temp = 1;
			b += a[i];
			js++;
			}
		}
		for(int j = js - 1; j >= 0; j--){
			printf("%c", b[j]);
		}
		}
	}
	if(t == 4){
		if(l == 2){
			printf("%c", a[0]);
		}
		else {
			for(int i = l - 2; i >= 0; i--){
		if(a[i] == '0' && temp == 0) continue;
		if(a[i] != '0' || (a[i] == '0' && temp == 1) || (i == 0 && a[i] == '0')){
			temp = 1;
			printf("%c", a[i]);
			} 
		}
		}
		printf("%c", a[l - 1]);
	}
	
	return 0;
}

13和15WA了,求大佬指正

2020/9/14 23:23
加载中...