Link It's a simple problem with a simple solution, But still I'm not able to figure out why is there runtime error on a couple of test cases.
Program
# | User | Rating |
---|---|---|
1 | Radewoosh | 3759 |
2 | orzdevinwang | 3697 |
3 | jiangly | 3662 |
4 | Benq | 3644 |
5 | -0.5 | 3545 |
6 | ecnerwala | 3505 |
7 | tourist | 3486 |
8 | inaFSTream | 3478 |
9 | maroonrk | 3454 |
10 | Rebelz | 3415 |
# | User | Contrib. |
---|---|---|
1 | adamant | 172 |
2 | awoo | 167 |
3 | SecondThread | 163 |
4 | BledDest | 162 |
4 | Um_nik | 162 |
6 | maroonrk | 161 |
7 | nor | 159 |
8 | -is-this-fft- | 150 |
9 | Geothermal | 146 |
10 | TheScrasse | 143 |
RUNTIME ERROR for no reason!
Link It's a simple problem with a simple solution, But still I'm not able to figure out why is there runtime error on a couple of test cases.
string s;
map<char, int> pos;
bool comp(string s1, string s2) {
int len = min(s1.size(), s2.size());
for (int i = 0; i < len; ++i) {
if (pos[s1[i]] < pos[s2[i]]) return true;
else if (pos[s1[i]] > pos[s2[i]]) return false;
}
if (s1.size() == s2.size()) return true;
else {
if (len == s1.size()) return true;
else return false;
}
}
void solve()
{
cin >> s;
for (int i = 0; i < 26; ++i) {
pos[s[i]] = i;
pos['A' + s[i] - 'a'] = i + 26;
}
int n; cin >> n;
vector<string> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
sort(a.begin(), a.end(), comp);
for (int i = 0; i < n; ++i) cout << a[i] << endl;
cout << endl;
}
Name |
---|