第二个样例不过求调
  • 板块P1928 外星密码
  • 楼主HNLG
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/10/5 08:07
  • 上次更新2024/10/5 10:36:29
查看原帖
第二个样例不过求调
905266
HNLG楼主2024/10/5 08:07
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<string>
#include<cstring>
using namespace std;
stack<string>s;
string ans;
int main() {
	char input[50004];
	scanf("%s", input);
	int len = strlen(input);
	char pre = ' ';
	for (int i = 0; i < len; i++) {
		if (input[i] == '[') { pre = input[i]; continue; }
		if (pre == '[' && input[i] == ']'){pre=']';continue;}
		if (input[i] >= '1' && input[i] <= '9' && pre == '[') {
			string num;
			while (input[i] >= '1' && input[i] <= '9') { num += input[i]; i++; }
			s.push(num); i--; pre = input[i]; continue;
		}
		if (s.empty()) {
			ans += input[i]; pre = input[i]; continue;
		}

		if (!s.empty()) {
			string now;
			while (input[i] != ']') {
				now += input[i]; i++;
			}
			int flag = 0;
			while (!s.empty()) {
				int hh = stoi(s.top());

				s.pop();
				i++;
				string now1 = now;
				for (int j = 0; j < hh - 1; j++) {
					now += now1;
				}
			}
			i--;
			pre = ']';
			ans += now;
		}
	}
	printf("%s\n", ans.c_str());
	return 0;
} 
2024/10/5 08:07
加载中...