Submission #542848

# Submission time Handle Problem Language Result Execution time Memory
542848 2022-03-28T09:14:48 Z AlperenT Kemija (COCI22_kemija) C++17
50 / 50
1 ms 212 KB
#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();
    }
}

Compilation message

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 time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct