제출 #53480

#제출 시각아이디문제언어결과실행 시간메모리
53480baactree괄호 문자열 (CEOI16_match)C++17
0 / 100
3 ms360 KiB
#include <bits/stdc++.h>
using namespace std;
int n;
char str[100005];
int sum[100005];
int main() {
	scanf("%s", str + 1);
	n = strlen(str + 1);
	for (int i = 1; i <= n; i++)
		sum[i] = sum[i - 1] ^ (1 << (str[i] - 'a'));
	for (int i = 1; i <= n; i++) {
		if (str[i] >= 'a'&&str[i] <= 'z') {
			bool flag = false;
			for (int j = n; j > i; j--) {
				if (str[j] == str[i] && (sum[j] ^ sum[i - 1]) == 0) {
					str[i] = '(';
					str[j] = ')';
					flag = true;
					break;
				}
			}
			if (!flag)return !printf("-1\n");
		}
	}
	printf("%s\n", str + 1);
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

match.cpp: In function 'int main()':
match.cpp:7:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", str + 1);
  ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...