-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path737.cpp
More file actions
77 lines (64 loc) · 1.19 KB
/
737.cpp
File metadata and controls
77 lines (64 loc) · 1.19 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*****************************************
* (This comment block is added by the Judge System)
* Submission ID: 63211
* Submitted at: 2018-09-16 19:05:12
*
* User ID: 539
* Username: 55211931
* Problem ID: 737
* Problem Name: word count
*/
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
string word[1000];
string str;
int position = 0;
int countTimes[1000];
for (int i = 0;i < 1000;i++)
{
countTimes[i] = 1;
}
while (cin>>str)
{
bool add = true;
for (int i=0;i <= position;i++)
{
if (word[i] == str)
{
countTimes[i]++;
add = false;
}
}
if (add)
{
word[position] = str;
position++;
}
}
for (int i = 0;i < position;i++)
{
for (int j = i;j < position;j++)
{
if (word[i] > word[j])
{
int tempTimes;
string tempStr;
tempStr = word[i];
tempTimes = countTimes[i];
word[i] = word[j];
countTimes[i] = countTimes[j];
word[j] = tempStr;
countTimes[j] = tempTimes;
}
}
}
for (int j = 0;j <position;j++)
{
cout << word[j] <<" "<<countTimes[j]<< endl;
}
return 0;
}