Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cwchar>
- #include <cstring>
- #include <cmath>
- #include <cassert>
- #include <clocale>
- //typedef unsigned char Char;
- #define Char wchar_t
- void igets(Char* str)
- { fgetws(str, 1024, stdin); }
- using namespace std;
- const int bNum(4), bSize(1<<10), cSize(1<<5);
- wchar_t AlS('a'), AlE('z');
- Char buff[bNum][bSize];
- Char comm[cSize];
- #define rangeBuff(i, num) for (int i(0); i < wcslen(buff[num]); ++i)
- #define ifeq(s1, s2) if(!wcscmp(s1, s2))
- #define R wscanf
- #define W wprintf
- void input(Char* str, int count)
- {
- fgetws(str, count, stdin);
- str[wcslen(str) - 1] = 0;
- }
- void Clear()
- {
- for (int i(0); i < bNum; ++i) for (int j(0); j < bSize; ++j)
- buff[i][j] = 0;
- for (int i(0); i < cSize; ++i)
- comm[i] = 0;
- }
- void ruDowner(Char& a) { if (a >= L'А' and a <= L'Я') a += 32; }
- void enDowner(Char& a) { if (a >= L'A' and a <= L'Z') a += 32; }
- void letterDown(Char& a) { ruDowner(a); enDowner(a); }
- void shift(Char& a, int s)
- {
- s += a;
- int L = AlE - AlS + 1;
- if (a >= AlS and a <= AlE)
- {
- while (s < AlS) s += L;
- while (s > AlE) s -= L;
- assert(s >= AlS and s <= AlE);
- a = (Char)s;
- }
- }
- void shift(Char& a, Char s, int sign)
- {
- assert(s >= AlS and s <= AlE);
- int d = sign * (s - AlS);
- shift(a, d);
- }
- void norm(int num)
- { rangeBuff(i, num) letterDown(buff[num][i]); }
- void caesar(int num, int step)
- {
- W(L"Num = %d, step = %d\n", num, step);
- norm(num);
- rangeBuff(i, num) shift(buff[num][i], step);
- }
- int main()
- {
- setlocale(0, "");
- int a[8] = {};
- while( wcscmp(comm, L"end") and R(L"%ls", comm) > 0 )
- {
- W(L"You entered: %ls;\n", comm);
- ifeq(comm, L"read") { R(L"%d%*c", &(a[0])); W(L"Arg = %d\n", a[0]); input(buff[a[0]], bSize); W(L"Readed: %ls;\n", buff[a[0]]); }
- ifeq(comm, L"print") { R(L"%d", &(a[0])); W(L"Buff[%d] = %ls;\n", a[0], buff[a[0]]); }
- ifeq(comm, L"caesar") { R(L"%d%d%*c", &(a[0]), &(a[1]) ); caesar(a[0], a[1]); }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment