TOPIC
HINT please
DarKMasteR asked 2 years ago
sample input output work fine. but it still get WA. can anyone give me a hint? how can i handel the equal part
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
void display(string *s)
{
int i = 0;
while (s[i] != "\0")
{
cout << s[i];
i++;
}
cout << endl;
}
main()
{
int n;
string t1, t2;
getline(cin, t1);a
stringstream ss;
string s[51];
ss << t1;
ss >> n;
ss.clear();
while (n--)
{
getline(cin, t1);
ss << t1;
int i = 0;
while (ss >> t2)
{
s[i] = t2 + " ";
i++;
}
s[i] = "\0";
int idx;
for (i = 0; s[i] != "\0"; i++)
{
idx = i;
for (int j = i + 1; s[j] != "\0"; j++)
{
if (s[idx].length() < s[j].length())
{
idx = j;
}
}
if (idx != i)
{
swap(s[i], s[idx]);
}
}
s[i - 1].pop_back();
display(s);
ss.clear();
}
}
This topic has not been answered yet. Be the first!