-
Notifications
You must be signed in to change notification settings - Fork 2
/
cargame.cpp
73 lines (63 loc) · 1.26 KB
/
cargame.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <ctype.h>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
int main()
{
ll i, j, k;
ll longWords;
ll shortWords;
ll shortIndex;
bool found = false;
cin >> longWords >> shortWords;
vector<string> longW ( longWords );
vector<string>::iterator vecStrItr;
vector<string>::iterator bodgeItr;
string shortWord;
for (i = 0; i < longWords; i++)
{
cin >> longW[i];
}
for (i = 0; i < shortWords; i++)
{
cin >> shortWord;
shortWord[0] = tolower(shortWord[0]);
shortWord[1] = tolower(shortWord[1]);
shortWord[2] = tolower(shortWord[2]);
found = false;
for (vecStrItr = longW.begin(); !found && vecStrItr != longW.end(); vecStrItr++) //iterate through words
{
shortIndex = 0;
for (k = 0; !found && k < (*vecStrItr).size(); k++) //iterate along the long word
{
if ((*vecStrItr)[k] == shortWord[shortIndex])
{
shortIndex++;
if (shortIndex == 3)
{
bodgeItr = vecStrItr;
found = true;
}
}
}
}
if (found)
{
cout << *bodgeItr << "\n";
}
else
{
cout << "No valid word\n";
}
}
return 0;
}