Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////Частотная 1
- #include <fstream>
- #include <string>
- using namespace std;
- int main() {
- ifstream input("input.txt");
- ofstream output("output.txt");
- string str;
- getline(input, str);
- const int length = 26;
- int mas[length] = { 0 };
- for (int i = 0; i < str.size(); i++)
- {
- char symb;
- symb = toupper(str[i]);
- if ('A'<=symb && symb <='Z')
- {
- mas[symb - 'A']++;
- }
- }
- for (int i = 0; i < length; i++)
- {
- output << (char)(i + 'A') << " " << mas[i] << endl;
- }
- return 0;
- }
- //////////////// Частотная 2
- #include <fstream>
- #include <string>
- using namespace std;
- int main()
- {
- ifstream input("input.txt");
- ofstream output("output.txt");
- string str;
- getline(input, str);
- const int length = 26;
- int mas[length] = { 0 };
- for (int i = 0; i < str.size(); i++)
- {
- char symb;
- symb = toupper(str[i]);
- if ('A' <= symb && symb <= 'Z')
- {
- mas[symb - 'A']++;
- }
- }
- int mas2[length];
- for (int i = 0; i < length; i++)
- {
- mas2[i] = i;
- }
- for (int i = 0; i < length - 1; i++)
- {
- for (int j = 0; j < length - i - 1; j++)
- {
- if (mas[j] < mas[j + 1])
- {
- swap(mas[j], mas[j + 1]);
- swap(mas2[j], mas2[j + 1]);
- }
- }
- }
- for (int i = 0; i < length && mas[i] != 0; i++)
- {
- output << (char)(mas2[i] + 'A') << " " << mas[i] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment