Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <ctype.h>
- #include <string>
- using namespace std;
- void Skaityti(string& zinute)
- {
- string temps;
- ifstream fin("input.txt");
- while (getline(fin, temps))
- {
- zinute += temps;
- }
- }
- void Koduoti(const string& zinute, string& uzsifruota1, string& uzsifruota2)
- {
- string uzsifruota = "";
- char symbols[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'Y', 'J', 'K', 'L',
- 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Z',
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '•', ',', '?', '!', '-', '"', ';', ':' };
- string morze[] = { "•-", "-•••", "-•-•", "-••", "•", "••-•", "--•", "••••", "••",
- "-•--", "•---", "-•-", "•-••", "--", "-•", "---", "•--•", "--•-", "•-•", "•••",
- "-", "••-", "•••-", "•--", "-••-", "--••", "-----", "•----",
- "••---", "•••--", "••••-", "•••••", "-••••", "--•••", "---••", "----•", "••••••", "•-•-•",
- "••-••", "--••--", "-••••-", "•-••-•", "-•-•-•", "---•••" };
- for (auto x : zinute) //koduoti paprastai
- {
- for (int i = 0; i < 45; i++)
- {
- if (x == symbols[i] || (isalpha(x) && toupper(x) == symbols[i]))
- {
- uzsifruota1 += morze[i] + " ";
- break;
- }
- if (x == ' ')
- {
- uzsifruota1 += " ";
- break;
- }
- }
- }
- bool pora = false;
- string temps = "";
- for (int j = 0; j < zinute.length(); j++) //koduoti sukeiciant salia raides
- {
- for (int i = 0; i < 45; i++)
- {
- if (zinute[j] == symbols[i] || (isalpha(zinute[j]) && toupper(zinute[j]) == symbols[i]))
- {
- if (j + 1 < zinute.length())
- {
- uzsifruota2 += morze[i];
- }
- else
- {
- temps = morze[i] + " " + temps;
- if (pora)
- {
- uzsifruota2 += temps;
- pora = false;
- temps = "";
- }
- }
- break;
- }
- if (zinute[j] == ' ')
- {
- uzsifruota1 += " ";
- pora = false;
- break;
- }
- }
- }
- }
- void Spausdinti(const string& zinute)
- {
- ofstream fout("output.txt", ios::app);
- fout << zinute << endl << endl;
- }
- int main()
- {
- string zinute = "";
- string uzsifruota1, uzsifruota2;
- Skaityti(zinute);
- Koduoti(zinute, uzsifruota1, uzsifruota2);
- Spausdinti(uzsifruota1); //paprastai
- Spausdinti(uzsifruota2); //sukeiciant
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement