-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC++.cpp
More file actions
51 lines (47 loc) · 935 Bytes
/
C++.cpp
File metadata and controls
51 lines (47 loc) · 935 Bytes
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
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool findWord(string s, string word)
{
size_t pos = s.find(word);
if (pos != string::npos)
{
return true;
}
return false;
}
int findPos(string alphabet, char c)
{
return alphabet.find(c);
}
int main()
{
string alphabet;
getline(cin, alphabet);
string message;
getline(cin, message);
string word;
getline(cin, word);
int alphabetLength = alphabet.length();
int messageLength = message.length();
for (int A = 0; A < alphabetLength; A++)
{
for (int B = 1; B < alphabetLength; B++)
{
string s = "";
for (int i = 0; i < messageLength; i++)
{
int pos = findPos(alphabet, message[i]);
pos = ((pos + A) * B) % alphabetLength;
s += alphabet[pos];
}
if (findWord(s, word))
{
cout << s << endl;
return 0;
}
}
}
}