Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstring>
- #define _CTR_SECURE_NO_WARNINGS
- const int PHRASE_LEN = 9;
- using namespace std;
- string table[2] = { "the quick brown fox jumps over the lazy dog", "" };
- char trans(char ch)
- {
- for (int i = 0; table[0][i]; i++)
- {
- if (ch == table[1][i]) return table[0][i];
- }
- return ch;
- }
- int calcChars(string phrase, char ch) {
- int c=0;
- for(int i=0; phrase[i]; i++) {
- if(phrase[i] == ch) {
- c++;
- }
- }
- return c;
- }
- void ToDo()
- {
- const char phrase[] = "\2\2\3 \1\2\1\1\1 \1\2\4\1\1 \1\4\1 \1\2\1\1\1 \4\1\3\2 \2\2\3 \1\1\1\1 \1\4\1";
- ifstream in("input.txt");
- if (!in.is_open())
- {
- cout << "file not open";
- return;
- }
- bool isExists = false;
- int n;
- in >> n;
- char ** text = new char* [n];
- in.ignore(255, '\n'); //. пропустили первую строку
- for (int i = 0; i < n; i++)
- {
- text[i] = new char[80];
- in.getline(text[i], 80);
- if (text[i][strlen(text[i]) - 1] == '\r') text[i][strlen(text[i]) - 1] = 0;
- cout<<"\n";
- //if (strlen(text[i]) == strlen(phrase))
- //{
- if (isExists == false)
- {
- for (int j = 0; j < strlen(text[i]); j++)
- {
- if(text[i][j] == ' ' && phrase[j] == ' ') {
- cout<<" ";
- }
- if(text[i][j] != ' ' && phrase[j] != ' ') {
- cout<<calcChars(text[i], text[i][j])<<"|"<<(int)phrase[j]<<" ";
- }
- if (text[i][j] == ' ' && phrase[j] == ' ' ||
- (text[i][j] != ' ' && phrase[j] != ' '
- && phrase[j] == calcChars(text[i], text[i][j]))) {
- isExists = true;
- }
- else
- {
- isExists = false;
- break;
- }
- }
- if (isExists) table[1] = text[i];
- }
- }
- ofstream out("output.txt");
- if (isExists)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < strlen(text[i]); j++)
- {
- out << trans(text[i][j]);
- }
- out << "\n";
- }
- }
- else out << "No solution";
- out.close();
- in.close();
- }
- int main()
- {
- ToDo();
- //system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment