CSES - Datatähti 2020 alku - Results
Submission details
Task:Merkkijonot
Sender:Epe
Submission time:2019-10-01 19:41:41 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'char* convert(char*)':
input/code.cpp:15:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < strlen(temp); i++){
                    ~~^~~~~~~~~~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:53:40: error: 'foundend' was not declared in this scope
     for(auto el = found.begin(); el != foundend(); el = found.upper_bound(*el)){
                                        ^~~~~~~~
input/code.cpp:53:40: note: suggested alternative: 'found'
     for(auto el = found.begin(); el != foundend(); el = found.upper_bound(*el)){
                                        ^~~~~~~~
                                        found

Code

#include <bits/stdc++.h>
using namespace std;

unsigned int fact(unsigned int i){
    if(i == 0){
        return 1;
    }
    return i * fact(i-1);
}

char* convert(char* temp){
    static char arr[50];
    map<char, int> keys;
    int o = 0;
    for(int i = 0; i < strlen(temp); i++){
        auto it = keys.find(temp[i]);
        int p = -1;
        if(it == keys.end()){
            p=o;o++;
            keys.insert(pair<char,int>(temp[i], p));
        } else {
            p = it->second;
        }
        arr[i] = (char)(p+64);
        //cout << "i: " << i << " p:" << p << endl;
    }
    return arr;
}

bool error = false;

int main(){
    int amount;
    cin >> amount;

    multiset<vector<char>> found;

    int pairs = 0;


    for(int i = 0; i < amount; i++){
        char temp[50];
        cin >> temp;
        char *test = convert(temp);

        vector<char> vec(test, test + strlen(temp));
        /*if(found.find(vec) != found.end()){
            pairs+=found.count(vec);
        }*/
        found.insert(vec);
    }

    for(auto el = found.begin(); el != foundend(); el = found.upper_bound(*el)){
        int cou = found.count(*el);

        if(cou > 1){
            pairs+=(fact(cou)/(2*fact(cou-2)));
        }
    }

    cout << pairs << endl;
}