75分,求助大佬
查看原帖
75分,求助大佬
699506
WAHSWSSBSBSB楼主2022/8/22 13:54
#include <bits/stdc++.h>
using namespace std;

string getstr(string str) {
	reverse(str.begin(), str.end());
	int i = 0;
	for (; i < str.size(); i++) {
		if (str[i] != '0')
			break;
	}
	return str.substr(i);
}

int main() {
	string a;
	cin >> a;
	int b = -1;
	if (a == "0" || a.size() == 1)
		cout << a << endl;

	else if (a.find(".") != -1) {
		int b = a.find(".");
		string s1 = a.substr(0, b);
		string s2 = a.substr(b + 1, a.size() -b);
		int i = 0;

		for (; i < s2.size(); i++) {
			if (s2[i] != '0')
				break;

		}
		s2 = s2.substr(i);
		cout << getstr(s1) << "." << getstr(s2)<<endl;

	} else if (a.find("/") != -1) {
		int b = a.find("/");
		string s1 = a.substr(0, b);
		string s2 = a.substr(b + 1, a.size() - b);

		cout << getstr(s1) << "/" << getstr(s2) << endl;

	} else if (a[a.size() - 1] == '%') {
		a.erase(a.size() - 1);
		cout << getstr(a) << "%" << endl;

	} else {
		cout << getstr(a) << endl;
	}
	return 0;
}
2022/8/22 13:54
加载中...