TOPIC
time limit exceeded
DarKMasteR asked 2 years ago
can anyone tell me how can i solve the time limit exceed. and is there any easier method then this?
include
include
using namespace std;
main() { int n; cin >> n; getchar(); string t, ss[999],s[n];
for (int i = 0; i < n; i++)
{
getline(cin, t);
t.push_back(' ');
int p = 0;
for (int j = 0; j < t.length(); j++)
{
if (t[j] != ' ')
{
ss[p].push_back(t[j]);
}
else
{
ss[p].push_back(' ');
p++;
}
}
for (int j = 0; j < p; j++)
{
for (int k = j + 1; k < p; k++)
{
if (ss[j].length() < ss[k].length())
{
swap(ss[j], ss[k]);
}
}
}
for (int j = 0; j < p; j++)
{
cout<<ss[j];
}
}
}
This topic was solved and cannot recieve new replies.