-
-
Save nikoncode/e41bbde764ab87130859 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <windows.h> | |
| int main() { | |
| //Set windows-1251 codepage | |
| SetConsoleCP(1251); | |
| SetConsoleOutputCP(1251); | |
| //Memory init | |
| char * str = new char[100]; | |
| char * res = new char[100]; | |
| char * word_begin = str, *iterator, *iterator_two, *progress = res; | |
| int count = 0; | |
| //Reading | |
| puts("Ââåäèòå ñòðîêó: "); | |
| gets(str); //not-safe use fgets | |
| //task | |
| int length = strlen(str); | |
| for (int i = 0; i <= length; ++i) { | |
| iterator = str + i; | |
| //word break | |
| if (*iterator == ' ' || *iterator == '\0') { | |
| //counting | |
| for (iterator_two = word_begin; iterator_two < iterator; ++iterator_two) { | |
| if (*iterator_two == *(iterator - 1)) { | |
| count++; | |
| } | |
| } | |
| //adding first symbols | |
| while (count != 0) { | |
| *progress = *(iterator - 1); | |
| progress++; | |
| count--; | |
| } | |
| //copying word | |
| strncpy(progress, word_begin, iterator - word_begin + 1); | |
| progress += iterator - word_begin + 1; | |
| //move output ptr | |
| word_begin = iterator + 1; | |
| } | |
| } | |
| puts(res); | |
| //free mem | |
| delete [] str; | |
| delete [] res; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment