求助为什么会RE
查看原帖
求助为什么会RE
496340
Cangshu楼主2021/4/25 19:49
#include <bits/stdc++.h>
using namespace std;
char a[21];
void read (char *s) {
	char c = getchar();
	while (c == '\n' || c == '\r') c = getchar();
	while (c != '\n' && c != '\r') {
		*s = c;
		s++;
		c = getchar(); 
	}
	*s = '\0';
}
int main () {
	int len, where = 0, mod;
	char mark;
	read(a);
	len = strlen(a);
	if (a[len - 1] == '%') {
		if (a[len - 2] == '0' && len - 3 >= 0) len--;
		for (int i = len - 2; i >= 0; i--) 
			cout << a[i];
		cout << '%';
		return 0;
	}
	for (int i = 0; i < len; i++) {
		if (a[i] == '/' || a[i] == '.') {
			where = i;
			mark = a[i];
		}
	}
	mod = where;
	if (where != 0) {
		while (a[mod - 1] == '0' && mod - 2 >= 0) mod--;
		for (int i = mod - 1; i >= 0; i--) cout << a[i];
		cout << mark;
		while(a[len - 1] == '0' && len - 2 > where) len--;
		for (int i = len - 1; i > where; i--) {
			if (i == where + 1 && a[i] == '0' && len - 1 - where > 1) break;
			cout << a[i];
		}
	}
	else {
		while(a[len - 1] == '0' && len - 2 >= 0) len--;
		for (int i = len - 1; i >= 0; i--) 
		cout << a[i];
	}
	return 0;
}
2021/4/25 19:49
加载中...