-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
65 lines (46 loc) · 1.31 KB
/
main.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
#include <iostream>
#include <fstream>
#include <string>
#include <array>
#include <iterator>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
bool compare_first_char_string(const string &adj, const string &animal, int char_num){
int adj_len = adj.size();
int ani_len = animal.size();
if(adj_len < char_num || ani_len < char_num) return false;
for(int i = 0; i < char_num; i++){
//cout << adj[i] <<" - " << animal[i] << endl;
if(adj[i] != animal[i]){
return false;
}else{
//cout << "it is equal" << endl;
}
}
return true;
}
int main(){
set<string> adjs;
set<string> animals;
string str;
int chars_num = 4; // change this number to set number of statrting letter need tot make a match
//read adjetives from file into array
ifstream adjfile("adjectives.txt");
while(getline(adjfile, str)){
transform(str.begin(), str.end(), str.begin(), ::tolower);
adjs.insert(str);
}
//read animal list into animal array
ifstream animalfile("animal_list.txt");
while(getline(animalfile, str)){
transform(str.begin(), str.end(), str.begin(), ::tolower);
animals.insert(str);
}
for(auto adj : adjs){
for(auto animal : animals){
if(compare_first_char_string(adj, animal, chars_num)) cout << adj << " - " << animal << endl;
}
}
return 1;
}