
- •Исходная формулировка
- •Формальная постановка задачи
- •Контрольный пример
- •Пользовательские типы
- •Ограничение, условленное исполнением на компьютере
- •Организация интерфейса пользователя
- •Макеты ввода/вывода
- •Этапы трансляции
- •Средства обеспечения ввода/вывода
- •Параметры функций:
- •Алгоритм работы
- •Текст программы
- •Результаты работы программы
Алгоритм работы
inputStr
|
inputText
outText
|
outStr
|
ProcessText
|
Znaki
|
File
|
ProcessStr
|
ProcessStr
|
|
1
|
|
|
Текст программы
main.cpp
#include "types.h" #include "def.h" int main(){ setlocale(LC_ALL, "Russian"); ifstream f("inp.txt", ios::in); if (!f.is_open()) {cout << "Ошибка открытия исходного файла" << "\n";} ofstream out("out.txt", ios::out); if (!out.is_open()){cout << "Ошибка открытия файла записи" << "\n"; } StrT T; StrL str1; inputText(f,out,T); outText(out,T); outYB(T, out); return 0;}
|
types.h
#pragma once #include <iostream> #include <fstream> using namespace std; const unsigned G = 50; const unsigned V = 20; struct StrP { int Len; int nach; }; struct StrL { char S[G]; int Len; }; struct StrT { StrL T[V]; int Hei; };
|
def.h
#pragma once void inputText(ifstream& f, ofstream& out, StrT& T); void outText(ofstream& out, StrT& T); int Znaki(char sy); int FuncStr(ofstream& out, int nach, int kon, int z, StrL str1); void ProcessStr(ofstream& out, StrL str1);
|
intext.cpp void inputStr(ifstream& f, StrL& str1){ int j = 0, kol = 0; char s; int flag = 1; if (flag == 1) {f >> kol; // считывается число в кажой строке} s = ' '; int Gi = (kol <= G) ? kol : G; Gi = (kol <= 0) ? 0 : Gi; while (!f.eof() && (j < Gi)) {f >> s; if (s == '\n') { flag = 1; break;} str1.S[j] = s; j++;} str1.Len = j; if ((s != '\n') && (!f.eof())) { while (!f.eof()) { f >> s; if (s == '\n') { break; }}}} void inputText(ifstream& f, ofstream& out, StrT& T) { int i = 0, flag = 1, strings; char ss; f >> strings; out << "Считалось число " << strings; int Vi = (strings <= V) ? strings : V; Vi = (strings <= 0) ? 0 : strings; out << "\nПредварительное число строк " << Vi << "\n"; f.unsetf(ios::skipws); f >> ss; // считался ненужный "\n" while (!f.eof() && (i < Vi)) { inputStr(f, T.T[i]); i++; } T.Hei = i; out << "Процесс считывания завершился. "; out << "Итоговое количество строк в тексте " << T.Hei << "\n\n";}
|
outwords.cpp
int MaxLen(StrT T) { T.Max = 0; for (int i = 0; i < T.Hei; i++) { T.Max = (T.Max < T.P[i].Len) ? T.P[i].Len : T.Max;} return T.Max;} void OutStr(StrL& str1, ofstream& out) { for (int p = 0; p < str1.lenn; p++) { out << str1.S[p];}}
void OutBlock(ifstream& f, StrT& T, ofstream& out) { int ee = (vi < T.Hei) ? vi : T.Hei; for (int i = 0; i < ee; i++) { OutStr(T.T[i], out); out << "\n";}} int Znaki(char sy) { int flag = 0; char Z[12] = { '.','!','?',',',';',':','-','(',')','"','/',' ' }; for (int z = 0; z < 12; z++) { if (sy == Z[z]) { flag = 1; break;}} return flag;} int FuncStr(int nach, int kon, int z, StrL& str1){ kon++; char Gla[12] = { 'a', 'e', 'i', 'o', 'u', 'y','A','E','I','O','U','Y' }; char Sog[40] = { 'b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','z','B','C','D','F','G','H','J','K','L','M','N','P','Q','R','S','T','V','W','X','Z' }; char C[10] = { '0','1','2','3','4','5','6','7','8','9' }; int i, j; int buk = 0; for (i = nach; i < kon; i++) { for (j = 0; j < 10; j++) { if (str1.S[i] == C[j]) { buk= 1;}} } int f1 = 0; for (i = nach; i < kon; i = i + 2) { for (j = 0; j < 12; j++) { if (str1.S[i] == Gla[j]) { f1++;}}} int f2 = 0; for (i = nach + 1; i < kon; i = i + 2) { for (j = 0; j < 40; j++) { if (str1.S[i] == Sog[j]) { f2++;}}} int f3 = 0; for (i = nach; i < kon; i = i + 2) { for (j = 0; j < 40; j++) { if (str1.S[i] == Sog[j]) { f3++;}}} int f4 = 0; for (i = nach + 1; i < kon; i = i + 2) { for (j = 0; j < 12; j++) { if (str1.S[i] == Gla[j]) { f4++;}}} if (f1 + f2 == z) { buk= 2; if (z%2 == 0) { buk = 1011; } else { buk = 1010; } if (z == 1) { buk = 1010; }} if (f3 + f4 == z) { buk = 3; if (z % 2 == 0) { buk = 1110; } else { buk = 1111; } if (z == 1) { buk = 1111; }} return buk;} void OutLongWord(ofstream& out, ifstream& f,int NACH, int int B1[vi]; int B2[vi]; T.flag = 1; int bloks; int i = 0, j = 0; f.seekg(0, ios_base::beg); int N = 0, V = 0; int Kon = 0; f.unsetf(ios::skipws); while (T.flag != 2) { out << "\n ПОЛОСА " << i + 1 << "\n"; int Kon = PolosaKon(f, T, N, end); bloks = (MaxLen(T) + (sh - 1)) / sh; for (j; j < bloks; j++) { V = N + j * sh; out << "\n БЛОК " << j + 1 << "\n"; InputBlock(f, T, V, j, end); OutBlock(f, T, out); out << "\nподходящие слова: "; ProcessText(f, T, V, out, j, Start, End, B1, B2); out << "\n";} i++; j = 0; N = Kon + 2; bloks = 0; for (int l = 0; l < vi; l++) { Start[l] = -5; End[l] = -5; B1[l] = 0; B2[l] = 0;} out << "\n";}} #include "types.h" void outStr(ofstream& out, StrL& str1) { out << str1.Len; for (int j = 0; j < str1.Len; j++) { out << str1.S[j];}} int Znaki(char sy) { int flag = 0; char Z[12] = { '.','!','?',',',';',':','-','(',')','"','/',' ' }; for (int z = 0; z < 12; z++) { if (sy == Z[z]) { flag = 1; break;}} return flag;} int FuncStr(ofstream& out, int nach, int kon, int z, StrL str1) {kon++; char Gla[12] = { 'a', 'e', 'i', 'o', 'u', 'y','A','E','I','O','U','Y' }; charSog[40]= { 'b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','z','B','C','D','F','G','H','J','K','L','M','N','P','Q','R','S','T','V','W','X','Z' }; char C[10] = { '0','1','2','3','4','5','6','7','8','9' };int i, j; for (i = nach; i < kon; i++) { for (j = 0; j < 10; j++) { if (str1.S[i] == C[j]) { return 1;}}} int f1 = 0; for (i = nach; i < kon; i = i + 2) { for (j = 0; j < 12; j++) { if (str1.S[i] == Gla[j]) { f1++;}}} int f2 = 0; for (i = nach + 1; i < kon; i = i + 2) { for (j = 0; j < 40; j++) { if (str1.S[i] == Sog[j]) { f2++;}}} int f3 = 0; for (i = nach; i < kon; i = i + 2) { for (j = 0; j < 40; j++) { if (str1.S[i] == Sog[j]) { f3++;}}}
|
KON) { f.seekg(NACH, ios_base::beg); char bu; while (f.tellg() < KON+1) { f >> bu; out << bu;} out << " ";} void ProcessStr(ifstream& f, StrL str1, int V, ofstream& out, int indj, int ii, int Start[vi], int End[vi], StrP dl, int B1[vi], int B2[vi]) { int Sl; //случай int t; int B[sh][3] = { 0 }; int colvo = 0; for (t = 0; t < str1.lenn; t++) { if (Znaki(str1.S[t]) != 1) { int st = t; int e = t; for (e + 1; (Znaki(str1.S[e]) != 1); e++) { if (e >= str1.lenn) { break; }} int end = e - 1;t = e; B[colvo][0] = st; B[colvo][1] = end; B[colvo][2] = end - st + 1; colvo++;}} for (int co = 0; co < colvo; co++) { int letter = FuncStr(B[co][0], B[co][1], B[co][2], str1); if (letter >= 100) { if ((B[co][1] == sh - 1) && (B[co][0] == 0)) { Sl = 1; B1[ii] = letter / 100; if ((Start[ii] < 0) || (End[ii] != (dl.nach + indj * sh + B[co][0]) - 1)||(B1[ii] == B2[ii])) { Start[ii] = dl.nach + indj * sh + B[co][0];} End[ii] = dl.nach + sh * indj + B[co][1]; B2[ii] = letter % 100;} if ((B[co][1] < sh - 1) && (B[co][0] == 0)) { Sl = 2; B1[ii] = letter / 100; if ((Start[ii] < 0) || (End[ii] != (dl.nach + indj * sh + B[co][0]) - 1) || (B1[ii] == B2[ii])) { Start[ii] = dl.nach + indj * sh + B[co][0];} End[ii] = dl.nach + sh * indj + B[co][1];} if ((B[co][1] == sh - 1) && (B[co][0] > 0)) { Sl = 3; Start[ii] = dl.nach + indj * sh + B[co][0]; End[ii] = dl.nach + indj * sh + B[co][1]; B2[ii] = letter % 100;} if ((B[co][1] < sh - 1) && (B[co][0] > 0)) { Sl = 4; Start[ii] = dl.nach + indj * sh + B[co][0]; End[ii] = dl.nach + indj * sh + B[co][1];} if (End[ii] - Start[ii]>0) { OutLongWord(out, f, Start[ii], End[ii]);} if (Sl == 4) { Start[ii] = -5; End[ii] = -5; B1[ii] = 0; B2[ii] = 0; }} else { Start[ii] = -5; End[ii] = -5; B1[ii] = 0; B2[ii] = 0;}}} void ProcessText(ifstream& f, StrT T, int V, ofstream& out, int indj, int Start[vi], int End[vi], int B1[vi], int B2[vi]) { int ee = (vi < T.Hei) ? vi : T.Hei; for (int ii = 0; ii < ee; ii++){ ProcessStr(f, T.T[ii], V, out, indj, ii, Start, End, T.P[ii], B1, B2); out << " ";}} void File(ifstream& f, StrT& T, int& end, ofstream& out){ int Start[vi]; int End[vi]; int f4 = 0; for (i = nach + 1; i < kon; i = i + 2) { for (j = 0; j < 12; j++) { if (str1.S[i] == Gla[j]) { f4++; }}}
if ((f1 + f2 == z) || (f3 + f4 == z)) { for (int d = nach; d < kon; d++) { out << str1.S[d]; } out << ' ';} else { return 0; }}
|