求助大佬 3TLE+1RE
查看原帖
求助大佬 3TLE+1RE
982831
hhhhhoneycat楼主2023/8/19 20:58

出答案都没错的,但是从n=7/8开始,运行的表现就是所有字符串的结果很快出来,然后光标自己闪个3s左右才会执行return 0退出??所以直接就很多TLE了,RE我暂时还没想明白。

思路就是普通的模拟,前2*(n-4)步都有套路,把最中间的o*移到后面的--去,再把最后的**移到前面的--去;最后6步打表。

这个代码里写cout << s也都是空白,要我一个一个字符访问才能输出来。。不知道是哪里有问题

#include <iostream>
#include <string>
using namespace std;
string ans[6] = {"oooo****--", "ooo--***o*", "ooo*o**--*", "o--*o**oo*", "o*o*o*--o*", "--o*o*o*o*"}; 
int main() {
	int n, cnt = 0;
	cin >> n;
	int len = n * 2 + 2;
	string s;
	for (int i = 0; i < n; i++) s[cnt++] = 'o';
	for (int i = 0; i < n; i++) s[cnt++] = '*';
	s[cnt++] = '-';
	s[cnt++] = '-';
	int op = n - 4;
	while (op--) {
		for (int j = 0; j < len; j++)
			cout << s[j];
		cout << endl;
		int i = 0;
		for (; i < len; i++) {
			if (s[i] == '*')
				break;
		}
		s[i - 1] = s[i] = '-';
		for (i = i + 1; i < len; i++) {
			if (s[i] == '-') {
				s[i] = 'o';
				s[i + 1] = '*';
 			}
		}
		for (int j = 0; j < len; j++)
			cout << s[j];
		cout << endl;
		//cout << s << endl;
		for (i = len - 1; i > 0; i--) {
			if (s[i] == '*' && s[i - 1] == '*') {
				s[i] = s[i - 1] = '-';
				break; 
			}
		}
		for (i = i - 1; i > 0; i--) {
			if (s[i] == '-' && s[i - 1] == '-') {
				s[i] = s[i - 1] = '*';
				break;
			} 
		}
	}
	for (int i = 0; i < 6; i++) {
		cout << ans[i];
		for (int j = 10; j < len; j++)
			cout << s[j];
		cout << endl;
	}
	return 0;
}
2023/8/19 20:58
加载中...