Here is the problem link: PROBLEM
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
for (int x = 1; x <= t; ++x)
{
int n;
cin >> n;
vector <string> names(n);
for (int i = 0; i < n; ++i) cin >> names[i];
sort(names.begin(), names.end());
int letters = -1;
string leader;
for (int i = 0; i < n; ++i)
{
set <char> chars;
for (int j = 0; j < names[i].size(); ++j)
if (names[i][j] != ' ')
chars.insert(names[i][j]);
if (static_cast <int> (chars.size()) > letters)
{
letters = static_cast <int> (chars.size());
leader = names[i];
}
}
cout << "Case #" << x << ": " << leader << '\n';
}
}
This works fine when there is no space in the input.
For example, if the input is
1
1
KICKSTART
then there are no issues.
But if the input is
1
1
GOOGLE KICKSTART
it only considers GOOGLE
and ignores KICKSTART
.
How do I fix this issue?