답안 #1032656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1032656 2024-07-24T05:35:52 Z 김은성(#10965) 괄호 문자열 (CEOI16_match) C++17
0 / 100
0 ms 440 KB
#include <bits/stdc++.h>
using namespace std;
char s[100009], t[100009];
int cnt[128], cur[128];
int main(){
    int n, i;
    scanf(" %s", s);
    n = strlen(s);
    for(i=0; i<n; i++)
        cnt[s[i]]++;
    for(i=97; i<=122; i++){
        if(cnt[i]%2==1){
            printf("-1\n");
            return 0;
        }
    }
    vector<int> x;
    for(i=0; i<n; i++){
        if(cur[s[i]] < cnt[s[i]]/2){
            t[i] = '(';
            x.push_back(s[i]);
        }
        else{
            t[i] = ')';
            if(x.back() != s[i]){
                printf("-1\n");
                return 0;
            }
            x.pop_back();
        }
        cur[s[i]]++;
    }
    printf("%s\n", t);
    return 0;
}

Compilation message

match.cpp: In function 'int main()':
match.cpp:10:16: warning: array subscript has type 'char' [-Wchar-subscripts]
   10 |         cnt[s[i]]++;
      |             ~~~^
match.cpp:19:19: warning: array subscript has type 'char' [-Wchar-subscripts]
   19 |         if(cur[s[i]] < cnt[s[i]]/2){
      |                ~~~^
match.cpp:19:31: warning: array subscript has type 'char' [-Wchar-subscripts]
   19 |         if(cur[s[i]] < cnt[s[i]]/2){
      |                            ~~~^
match.cpp:31:16: warning: array subscript has type 'char' [-Wchar-subscripts]
   31 |         cur[s[i]]++;
      |             ~~~^
match.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     scanf(" %s", s);
      |     ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 440 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 440 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 440 KB Output isn't correct
3 Halted 0 ms 0 KB -