-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring-sort.cpp
More file actions
63 lines (54 loc) · 1.12 KB
/
string-sort.cpp
File metadata and controls
63 lines (54 loc) · 1.12 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<iostream>
#include<string>
#include<vector>
using namespace std;
vector<string> a;
vector<string> b;
int flag = 0;
int counta = 0;
int countb = 0;
void sort(vector<string> a, vector<string> b);
int main()
{
//int inpt=0;
string inpt;
for (int i = 0; inpt != "end"; i++) //a[i-1]!="end"
{
cin >> inpt;
a.push_back(inpt);
counta++;
}
counta--;
//------------------------将a[i]插入b[i]中的正确位置---------------------------------//
for (int i = 0; i < counta; i++)
{
//string end;
for (int j = 0; j < countb; j++)
{
//找到第一个大于a[i]的b[j]
//将a[i]插入到b[j]之前的位置
if (a[i]<b[j])
{
b.insert(b.begin() + j, a[i]);
countb++;
flag = 1;
//end = b[countb];
break;
}
}
if (flag == 0) {
b.push_back(a[i]);
countb++;
}
flag = 0;
}
//--------------------------------------------------------------------------------//
for (int i = 0; i<(countb-1); i++)
{
cout << b[i] << ',';
}
cout << b[countb - 1] << endl;
//a.push_back("long");
system("pause");
return 0;
}