求助!60分!
查看原帖
求助!60分!
773235
dctc1494楼主2024/7/23 11:22

我写了个C++代码,但是5AC,5WA,拿了50分,不知道怎么回事,有没有大佬来帮帮我的。

#include <bits/stdc++.h>

using namespace std;

bool flag = false;
int tmp = 0, x = 1;
string str, s_tmp = "", res = "";

int main(void) {
	ios::sync_with_stdio(false);
	cin >> str;
	for (int i = 0; i < str.size(); ++i) {
		if (str[i] != '[' && str[i] != ']' && tmp == 0) {
			res += str[i];
		} else if (str[i] != '[' && str[i] != ']' && tmp != 0) {
			s_tmp += str[i];
		} else if (str[i] == '[') {
			++tmp;
//			cout << str[i + 2] << " " << ('0' <= str[i + 2] && str[i + 2] <= '9') << endl;
			if ('0' <= str[i + 2] && str[i + 2] <= '9') {
//				cout << ((str[i + 1] - '0') * 10 + str[i + 2] - '0') << endl;
				x *= ((str[i + 1] - '0') * 10 + str[i + 2] - '0');
				i += 2;
			} else {
				x *= str[i + 1] - '0';
				++i;
			}
		} else if (str[i] == ']') {
			--tmp;
			if (tmp == 0) {
				for (int j = 0; j < x; ++j) {
//					cout << s_tmp << endl;
					res += s_tmp;
				}
				x = 1;
				s_tmp = "";
			}
		}
	}
	cout << res << endl;

	return 0;
}
2024/7/23 11:22
加载中...