-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBus Number.cpp
54 lines (46 loc) · 954 Bytes
/
Bus Number.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
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
int main()
{
using namespace std;
bool *busTotal = new bool[1001];
int numOfBus;
int busNum;
int specialCount = 0;
int start = 0;
int end = 0;
cin >> numOfBus;
for (int i = 0; i < numOfBus; i++) { cin >> busNum;
busTotal[busNum] = true;
}
for(int i = 1; i < 1001; i++)
{
if (busTotal[i] == true)
{
specialCount++;
if (specialCount == 2)
{
if (busTotal[i+1] == true)
{
start = i-1;
}
else
{
cout << i-1 << " " << i << " "; } } if (specialCount > 1 && busTotal[i+1] == true)
{
continue;
}
else if (specialCount > 2)
{
cout << start << "-" << i << " ";
}
else if(busTotal[i+1] == false && busTotal[i-1] == false)
{
cout << i << " ";
}
}
else {
specialCount = 0;
}
}
return 0;
}