제출 #43847

#제출 시각아이디문제언어결과실행 시간메모리
43847ngkan146괄호 문자열 (CEOI16_match)C++11
0 / 100
1 ms356 KiB
#include <bits/stdc++.h>
using namespace std;
string s;
int cnt[256], cnt2[256];
int main(){
    iostream::sync_with_stdio(0);
    cin >> s;
    for(auto v: s)
        ++ cnt[v];
    for(auto v: cnt){
        if (cnt[v] % 2){
            cout << -1;
            exit(0);
        }
    }
    string res;
    for(auto v: s){
        res.push_back((++cnt2[v] <= cnt[v]/2 ? '(' : ')'));
    }
    // check
    stack <char> st;
    for(int i=0;i<res.size();i++){
        if (res[i] == '(')
            st.push(s[i]);
        else{
            if (st.top() != s[i]){
                cout << -1;
                exit(0);
            }
            st.pop();
        }
    }
    cout << res;
    //
}

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

match.cpp: In function 'int main()':
match.cpp:9:17: warning: array subscript has type 'char' [-Wchar-subscripts]
         ++ cnt[v];
                 ^
match.cpp:18:32: warning: array subscript has type 'char' [-Wchar-subscripts]
         res.push_back((++cnt2[v] <= cnt[v]/2 ? '(' : ')'));
                                ^
match.cpp:18:42: warning: array subscript has type 'char' [-Wchar-subscripts]
         res.push_back((++cnt2[v] <= cnt[v]/2 ? '(' : ')'));
                                          ^
match.cpp:22:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<res.size();i++){
                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...