75分求调,样例都正确
查看原帖
75分求调,样例都正确
1462322
Peddy楼主2024/9/22 13:54
#include<iostream>
#include<string>
using namespace std;

int main() {
	int pos;
	string s;
	cin >> s;
	pos = int(s.find("."));
	if (pos != -1) {
		int i = pos - 1;
		while (i >= 0 && s[i] == '0') i--;
		if (i < 0) cout << 0;
		for ( ; i >= 0; i--)
			cout << s[i];
		cout << '.';
		int j = pos + 1;
		while (s[j] == '0') j++;
		if (j == (int)s.length()) cout << 0;
		for (i = (int)s.length(); i >= j; i--)
			cout << s[i];
		return 0;
	}
	pos = int(s.find("/"));
	if (pos != -1) {
		int i = pos - 1;
		while (i >= 0 && s[i] == '0') i--;
		if (i < 0) cout << 0;
		for ( ; i >= 0; i--)
			cout << s[i];
		cout << '/';
		i = (int)s.size();
		while (s[i] == 0) i--;
		if (i == pos) cout << 0;
		for ( ; i > pos; i--)
			cout << s[i];
		return 0;
	}
	pos = int(s.find("%"));
	if (pos != -1) {
		int i = pos - 1;
		while (i >= 0 && s[i] == '0') i--;
		if (i < 0) cout << 0;
		for ( ; i >= 0; i--)
			cout << s[i];
		cout << '%';
		return 0;
	}
	
	int i = int(s.length()) - 1;
	while (i >= 0 && s[i] == '0') i--;
	if (i < 0) cout << 0;
	for ( ; i >= 0; i--)
		cout << s[i];
	return 0;
}
2024/9/22 13:54
加载中...