Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- char words[30][12];
- int main()
- {
- int str_size = 1000;
- char * str = (char *) calloc(str_size, sizeof(char));
- int len_str = 0;
- // 1) считываем строку
- while(1)
- {
- str[len_str] = getchar();
- ++len_str;
- if (len_str == str_size-1)
- {
- str_size += 500;
- str = realloc(str, str_size);
- }
- if (str[len_str-1] == '.') // если ".", то закончить
- {
- str[len_str] = 0; // отмечаем, что строка окончилась
- break;
- }
- }
- int cnt = 0, j = 0; // cnt - количество слов, j - длина текущего слова
- for(int i=0; i < len_str; ++i)
- {
- if (str[i] == ' ' && i > 0 && str[i-1] != ' ')
- {
- cnt ++;
- j = 0;
- }
- else
- {
- if (str[i] != ' ')
- {
- words[cnt][j] = str[i];
- ++j;
- }
- }
- }
- // вывод по словам
- printf("Words:\n");
- for(int i=0; i<cnt; ++i)
- {
- if ( strcmp(words[i], words[cnt]) ) // strcmp = 0, если строки равны
- {
- int m = strlen(words[i]); // длина строки
- char first = words[i][0];
- for(int j=0; j<m-1; ++j)
- words[i][j] = words[i][j+1];
- words[i][m-1] = first;
- printf("%d %s\n", m, words[i]);
- }
- }
- // вывод исходной строки
- printf("\nSource string: %s\n\n", str);
- free(str);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment