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
|
/*
Challenge 117
TASK #1 � Missing Row
Submitted by: Mohammad S Anwar
You are given text file with rows numbered 1-15 in random order but there is a
catch one row in missing in the file.
11, Line Eleven
1, Line one
9, Line Nine
13, Line Thirteen
2, Line two
6, Line Six
8, Line Eight
10, Line Ten
7, Line Seven
4, Line Four
14, Line Fourteen
3, Line three
15, Line Fifteen
5, Line Five
Write a script to find the missing row number.
*/
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
const int NUM_LINES = 15;
int main() {
bool found[NUM_LINES] = { 0 };
string line;
while (getline(cin, line)) {
istringstream iss{ line };
int n;
iss >> n;
if (n >= 1 && n <= NUM_LINES)
found[n - 1] = true;
}
string separator = "";
for (int n = 1; n <= NUM_LINES; n++) {
if (!found[n - 1]) {
cout << separator << n;
separator = ", ";
}
}
cout << endl;
}
|