Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <string.h>
- #include <iostream>
- using namespace std;
- int main() {
- const int MAX = 4000;
- char str[MAX];
- char new_str[MAX] = { 0 };
- const char DELIMS[] = " .,:;!?-\'()";
- char *word, *Ntr;
- cout << "Enter a string: ";
- cin.getline(str, MAX);
- word = strtok_s(str, DELIMS, &Ntr);
- while (word != NULL) {
- int cnt_no_repeat = 0;
- int cnt_repeat = 0;
- int ptr_len = strlen(word) + 1;
- char *ptr_temp = new char[ptr_len];
- strcpy_s(ptr_temp, ptr_len, word);
- for (int i = 0; ptr_temp[i]; i++) {
- if (ptr_temp[i] == ' ') continue;
- char ch_tmp = ptr_temp[i];
- ptr_temp[i] = ' ';
- char *b = strchr(ptr_temp, ch_tmp);
- if (b != NULL) {
- cnt_repeat++;
- for (int j = b - ptr_temp; ptr_temp[j]; j++) {
- if (ptr_temp[j] == ch_tmp)
- ptr_temp[j] = ' ';
- }
- }
- else cnt_no_repeat++;
- }
- if (cnt_repeat > cnt_no_repeat) {
- strcat_s(new_str, word);
- int len = strlen(new_str);
- new_str[len] = ' ';
- new_str[len + 1] = 0;
- }
- word = strtok_s(NULL, DELIMS, &Ntr);
- }
- cout << endl << new_str << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement