Task: | Merkkijonot |
Sender: | Tempo |
Submission time: | 2019-10-03 10:10:06 +0300 |
Language: | C++ (C++11) |
Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:31:11: error: found ':' in nested-name-specifier, expected '::' for(i : inputs) ^ input/code.cpp:31:9: error: 'i' has not been declared for(i : inputs) ^ input/code.cpp:45:5: error: expected primary-expression before 'if' if (duplicates > 1) ^~ input/code.cpp:45:5: error: expected ';' before 'if' input/code.cpp:45:5: error: expected primary-expression before 'if' input/code.cpp:45:5: error: expected ')' before 'if' input/code.cpp:49:11: error: found ':' in nested-name-specifier, expected '::' for(i : inputs) ^ input/code.cpp:49:9: error: 'i' has not been declared for(i : inputs) ^ input/code.cpp:53:5: error: expected primary-expression before 'return' return 0; ^~~~~~ input/code.cpp:53:5: error: expected ')' before 'return' input/code.cpp:29:9: warning: unused variable 'prev_item' [-Wunused-variable] int prev_item = 0; ^~~~~~~~~
Code
#include <iostream> #include <algorithm> #include <vector> #include <map> #include <iterator> #include <string> using namespace std; int convert(string); int main() { int n; cin >> n; vector<int> inputs; for(int i=0; i<n; i++) { string s; cin >> s; inputs.push_back(convert(s)); } sort(inputs.begin(), inputs.end()); int duplicates = 1; int pairs = 0; int prev_item = 0; for(i : inputs) { if(i == prev_item) duplicates++; else { cout << duplicates; for (int j = 1; j < duplicates; j++) pairs += j; duplicates = 1; } prev_item = i; } if (duplicates > 1) for (int j = 1; j < duplicates; j++) pairs += j; for(i : inputs) cout << i << endl; cout << pairs; return 0; } int convert(string s) { map<char,int> cmap; map<char,int>::iterator it; int val = 0; string converted = "9"; for(const char & c : s) { if(cmap.find(c) == cmap.end()) { cmap.insert(pair<char,int>(c,val)); val++; } for (it = cmap.begin(); it != cmap.end(); it++) if (c == it->first) converted.append(to_string(it->second + 1)); } return stoi(converted); }