200D - Programming Language - CodeForces Solution


binary search brute force expression parsing implementation *1800

Please click on ads to support us..

C++ Code:

#include<iostream>
#include<map>
#include<string>
#include<vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    map<string, vector<vector<char>>> f;
    for(int i = 0; i < n; i++) {
        string s; // function name
        cin >> s; // read "void"
        s.clear();
        for (char c; cin.get(c);) {
            if (c == ' ')
                continue; // spaces is not a part of the name
            else if (c == '(')
                break;
            else
                s.push_back(c);
        }

        vector<char> a;
        string t;
        for (char c; cin.get(c);) {
            if (c == ' ')
                continue;
            else if (c == ')') {
                a.push_back(t[0]);
                break;
            }
            else if (c == ',') {
                a.push_back(t[0]);
                t.clear();
            }
            else
                t.push_back(c);
        }
        
        f[s].push_back(a);
    }

    int m;
    cin >> m;
    map<string, char> v;
    for(int i = 0; i < m; i++) {
        string t, s;
        cin >> t >> s;
        v[s] = t[0];
    }

    int k;
    cin >> k;
    for(int i = 0; i < k; i++) {
        string s;
        for (char c; cin.get(c);) {
            if (c == ' ')
                continue;
            if(c == '\n')
                continue; // line reading ends at ')' so line break become unread
            else if (c == '(')
                break;
            else
                s.push_back(c);
        }

        vector<char> a;
        string t;
        for (char c; cin.get(c);) {
            if (c == ' ')
                continue;
            else if (c == ')') {
                a.push_back(v[t]);
                break;
            }
            else if (c == ',') {
                a.push_back(v[t]);
                t.clear();
            }
            else
                t.push_back(c);
        }

        int c = 0; // number of suitable functions
        for (auto t : f[s]) {
            if (t.size() != a.size())
                continue;

            for (int j = 0; j < a.size(); j++) {
                if (t[j] != 'T' && t[j] != a[j])
                    goto next;
            }
            c++;
        next:;
        }

        cout << c << endl;
    }
}/*1691106019.359995*/


Comments

Submit
0 Comments
More Questions

1591A - Life of a Flower
1398C - Good Subarrays
629A - Far Relative’s Birthday Cake
1166A - Silent Classroom
1000B - Light It Up
218B - Airport
1463B - Find The Array
1538C - Number of Pairs
621B - Wet Shark and Bishops
476B - Dreamoon and WiFi
152C - Pocket Book
1681D - Required Length
1725D - Deducing Sortability
1501A - Alexey and Train
721B - Passwords
1263D - Secret Passwords
1371B - Magical Calendar
1726E - Almost Perfect
1360C - Similar Pairs
900A - Find Extra One
1093D - Beautiful Graph
748A - Santa Claus and a Place in a Class
1511B - GCD Length
676B - Pyramid of Glasses
597A - Divisibility
1632A - ABC
1619D - New Year's Problem
242B - Big Segment
938A - Word Correction
159C - String Manipulation 10