Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstring>
- #include <iostream>
- using namespace std;
- #define MAX_WORDS_UNIQUE 255
- #define WORD_MAX 80
- #define isUpper(ch) ((ch) >= 'A' && (ch) <= 'Z')
- #define isLower(ch) ((ch) >= 'a' && (ch) <= 'z')
- bool isAlpha(char ch)
- {
- return isUpper(ch) || isLower(ch) || ch == '\'';
- }
- char toUpper(char ch)
- {
- return isLower(ch) ? ch - 'a' + 'A' : ch;
- }
- char toLower(char ch)
- {
- return isUpper(ch) ? ch - 'A' + 'a' : ch;
- }
- void get_word(char* buffer, int size)
- {
- int ptr = 0;
- char ch;
- while (cin.get(ch)) {
- if (isAlpha(ch)) {
- buffer[ptr++] = toLower(ch);
- } else if (ptr > 0) {
- buffer[ptr++] = '\0';
- return;
- }
- }
- }
- int main()
- {
- freopen("in.txt", "r", stdin);
- char words[MAX_WORDS_UNIQUE][WORD_MAX] = { 0 };
- int cnt[MAX_WORDS_UNIQUE] = { 0 };
- char buffer[WORD_MAX] = { 0 };
- while (cin) {
- get_word(buffer, WORD_MAX);
- int idx = 0;
- while (words[idx][0] != '\0' && idx < MAX_WORDS_UNIQUE) {
- if (strcmp(buffer, words[idx]) == 0) {
- cnt[idx]++;
- break;
- } else {
- idx++;
- }
- }
- if (idx < MAX_WORDS_UNIQUE && words[idx][0] == '\0') {
- strcpy(words[idx], buffer);
- cnt[idx]++;
- }
- buffer[0] = '\0';
- }
- for (int i = 0; i < MAX_WORDS_UNIQUE; i++) {
- if (words[i][0]) {
- cout << words[i] << "\t" << cnt[i] << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement