-
Notifications
You must be signed in to change notification settings - Fork 0
/
0004_For_Loop.cpp
37 lines (36 loc) · 924 Bytes
/
0004_For_Loop.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
/*https://www.hackerrank.com/challenges/c-tutorial-for-loop/problem*/
#include <iostream>
#include <vector>
#include <string>
void buildList(std::vector<std::string> &list){
list.push_back("one");
list.push_back("two");
list.push_back("three");
list.push_back("four");
list.push_back("five");
list.push_back("six");
list.push_back("seven");
list.push_back("eight");
list.push_back("nine");
}
void print(std::vector<std::string> &list, unsigned i){
if (i <10U)
std::cout << list[--i] << "\n";
else{
if (i %2 == 0)
std::cout << "even" << "\n";
else
std::cout << "odd" << "\n";
}
}
int main() {
// Complete the code.
std::vector<std::string> list;
buildList(list);
unsigned first, last;
std::cin >> first >> last;
for(;first <= last; ++first){
print(list, first);
}
return EXIT_SUCCESS;
}