include stdafx include iostream include fstream include conio include

 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>
using namespace std;
bool check(string NewStr, char x)
{
bool chk1 = false;
int len = NewStr.length(), cnt = 0;
for (int i = 0; i < len; i++)
{
if (NewStr[i] == x)
cnt += 1;
}
if (cnt > 1)
chk1 = true;
return chk1;
}
string sort(string NewStr)
{
string SortedStr = "", temp, buff[200];
int cnti = 0,cntj = 0;
int len = NewStr.length();
while (cnti < len)
{
while (!isspace(NewStr[cnti]))
{
temp += NewStr[cnti];
cnti++;
}
buff[cntj] += temp;
cnti++;
cntj++;
temp = "";
}
for (int i = 0; i < cntj; i++)
for (int j = i + 1; j < cntj; j++)
{
int len1 = buff[i].length();
int len2 = buff[j].length();
if (len1 > len2)
swap(buff[j], buff[i]);
}
for (int i = 0; i < cntj; i++)
SortedStr += buff[i] + " ";
return SortedStr;
}
int _tmain(int argc, _TCHAR* argv[])
{
setlocale(LC_CTYPE, "rus");
int cnti = 0, cnt = 0;
string str1,str2, temp = "", srt = "";
char x;
bool chk = false;
ifstream file("text.txt");
getline(file, str1, '\0');
file.close();
int len = str1.length();
cout << str1;
cout << "\n\nЗадайте букву\n";
cin >> char(x);
while (cnti < len)
{
while ((!ispunct(str1[cnti])) && (!isspace(str1[cnti])))
{
temp += str1[cnti];
cnti++;
}
chk = check(temp, x);
if (chk)
str2 += temp + " ";
temp = "";
cnti++;
chk = false;
}
srt = sort(str2);
cout << '\n' << str2 << '\n';
cout << '\n' << srt << '\n';
_getch();
return 0;
}