MLE求助 我不理解5555
查看原帖
MLE求助 我不理解5555
323183
CLCK楼主2022/9/11 21:05

如题

不知道为什么MLE

是不是字符串处理哪里有问题

求助 /kk

#include <iostream>
#include <algorithm>
using namespace std;
string s[10];
int n[10];
string ss[30] = {
"one", "two", "three", "four", "five",
"six", "seven", "eight",  "nine", "ten",
"eleven", "twelve", "thirteen", "fourteen", "fifteen", 
"sixteen", "seventeen", "eighteen", "nineteen", "twenty", 
"a", "both", "another", "first", "second", "third"
};
int nn[30] = {
1, 2, 3, 4, 5, 
6, 7, 8, 9, 10, 
11, 12, 13, 14, 15, 
16, 17, 18, 19, 20, 
1, 2, 1, 1, 2, 3
};
void read() {
	while (1) {
		int i = 0;
		char x;
		cin >> x;
		if (x == '.' || x == '\n') break;
		while (x != ' ' && x != '\n') {
			s[i] += x;
		}
		i++;
	}
	return ;
}
void check() {
	for (int i = 0; i < 6; i++) {
		for (int j = 0; j < 30; j++) {
			if (s[i] == ss[j]) {
				n[i] = nn[j];
			}
		}		
	}
	return ;
}

int main() {
	read();
	check();
	for (int i = 0; i < 6; i++) {
		n[i] *= n[i];
		n[i] %= 100;
	}
	sort(n, n + 6);
	for (int i = 0; i < 6; i++) {
		if (n[i] < 10 && n[i] != 0) cout << '0'; 
		if (n[i] != 0) cout << n[i];
	}
	cout << endl;
}

2022/9/11 21:05
加载中...