-
Notifications
You must be signed in to change notification settings - Fork 0
/
bai4.cpp
43 lines (40 loc) · 835 Bytes
/
bai4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <bits/stdc++.h>
using namespace std;
struct comp
{
bool operator()(string const &i, string const &j) const
{
return i > j;
}
};
string combine(const vector<string> &words)
{
string s;
vector<string> temp;
for (int i = 0; i < words.size(); i++)
{
temp.push_back(words[i]);
}
sort(temp.begin(), temp.end(), comp());
for (int i = 0; i < temp.size(); i++)
{
if (i < temp.size() - 1)
{
s += temp[i];
s += " ";
}
else
s += temp[i];
}
return s;
}
/* this is test case.
int main()
{
string s[] = {"this", "is", "a", "test"};
vector<string> words(s, s + 4);
string combined = combine(words);
cout << combined << endl;
cout << boolalpha << ("this test is a" == combined);
}
*/