Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // разработать рекурсивную функцию принимающую символьную строку
- // и выполняющую переворот последнего слова доп строк не использовать
- #include <stdio.h>
- #include <stdlib.h>
- void revLast(char *str, int i, int j){
- static int flag = 0;
- static int index = 0;
- static int space = 0;
- static int count = 0;
- if(str[index + 1] == '\0'){
- flag = 1;
- }
- if(str[index] == ' '){
- space = index;
- }
- if(flag == 0){
- index++;
- revLast(str, space + 1, index);
- return;
- }
- if(count <= (index - space) / 2){
- char tmp = str[i];
- str[i] = str[j];
- str[j] = tmp;
- count++, i++, j--;
- revLast(str, i, j);
- } else {
- return;
- }
- }
- int main(){
- char *str = (char*) malloc(1000 * sizeof(char));
- gets(str);
- puts(str);
- revLast(str, 0, 0);
- puts(str);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement