제출 #542848

#제출 시각아이디문제언어결과실행 시간메모리
542848AlperenTKemija (COCI22_kemija)C++17
50 / 50
1 ms212 KiB
#include <bits/stdc++.h>

using namespace std;

int n;

map<char, int> lft, rght;

string str;

void solve(){
    lft.clear(), rght.clear();

    cin >> str;

    int cur = 1;

    int ptr = 0;

    while(ptr != str.size()){
        if(isdigit(str[ptr])) cur = str[ptr++] - '0';
        else cur = 1;

        while(ptr != str.size() && str[ptr] != '+' && str[ptr] != '-'){
            if(ptr + 1 != str.size() && isdigit(str[ptr + 1])){
                lft[str[ptr]] += cur * (str[ptr + 1] - '0');

                ptr += 2;
            }
            else{
                lft[str[ptr]] += cur;

                ptr += 1;
            }
        }

        if(ptr != str.size() && str[ptr] == '+') ptr++;
        if(ptr != str.size() && str[ptr] == '-'){
            ptr += 2;
            break;
        }
    }

    while(ptr != str.size()){
        if(isdigit(str[ptr])) cur = str[ptr++] - '0';
        else cur = 1;

        while(ptr != str.size() && str[ptr] != '+' && str[ptr] != '-'){
            if(ptr + 1 != str.size() && isdigit(str[ptr + 1])){
                rght[str[ptr]] += cur * (str[ptr + 1] - '0');

                ptr += 2;
            }
            else{
                rght[str[ptr]] += cur;

                ptr += 1;
            }
        }

        if(ptr != str.size() && str[ptr] == '+') ptr++;
        if(ptr != str.size() && str[ptr] == '-'){
            ptr += 2;
            break;
        }
    }

    for(auto p : lft){
        if(rght[p.first] != p.second){
            cout << "NE\n";
            return;
        }
    }

    for(auto p : rght){
        if(lft[p.first] != p.second){
            cout << "NE\n";
            return;
        }
    }

    cout << "DA\n";
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    cin >> n;

    while(n--){
        solve();
    }
}

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

Main.cpp: In function 'void solve()':
Main.cpp:20:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     while(ptr != str.size()){
      |           ~~~~^~~~~~~~~~~~~
Main.cpp:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         while(ptr != str.size() && str[ptr] != '+' && str[ptr] != '-'){
      |               ~~~~^~~~~~~~~~~~~
Main.cpp:25:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |             if(ptr + 1 != str.size() && isdigit(str[ptr + 1])){
      |                ~~~~~~~~^~~~~~~~~~~~~
Main.cpp:37:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         if(ptr != str.size() && str[ptr] == '+') ptr++;
      |            ~~~~^~~~~~~~~~~~~
Main.cpp:38:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         if(ptr != str.size() && str[ptr] == '-'){
      |            ~~~~^~~~~~~~~~~~~
Main.cpp:44:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     while(ptr != str.size()){
      |           ~~~~^~~~~~~~~~~~~
Main.cpp:48:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         while(ptr != str.size() && str[ptr] != '+' && str[ptr] != '-'){
      |               ~~~~^~~~~~~~~~~~~
Main.cpp:49:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |             if(ptr + 1 != str.size() && isdigit(str[ptr + 1])){
      |                ~~~~~~~~^~~~~~~~~~~~~
Main.cpp:61:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         if(ptr != str.size() && str[ptr] == '+') ptr++;
      |            ~~~~^~~~~~~~~~~~~
Main.cpp:62:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         if(ptr != str.size() && str[ptr] == '-'){
      |            ~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...