Добавил:
Upload
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:prg-sem-sp / 2 / Задача2
.CPP// ‡ ¬Ґ б«®ў
#include <stdio.h>
#include <string.h>
#include <alloc.h>
#include <stdlib.h>
#include <conio.h>
#define ENTER 13
int main()
{int i=0,j=0,max=0,max1=0,max2=0,begin=0;
char ch,word1[90],word2[90];
char*input=(char*)calloc(350,sizeof(char));
clrscr();
puts("‚ўҐ¤ЁвҐ ⥪бв(ENTER-®Є®з ЁҐ ўў®¤ ):");
for(i=0;((ch=getche())!=ENTER)&&(i<299);i++)
{input[i]=ch;
}input[i]=NULL;max=strlen(input);
puts("\n‚ўҐ¤ЁвҐ б«®ў :");
gets(word1);max1=strlen(word1);
gets(word2);max2=strlen(word2);
i=0;
while(input[i]!=NULL)
{if(i==0||input[i-1]==' ')
{begin=i;char*word=(char*)calloc(90,sizeof(char));int z=0;
while(input[i]!=' '&&input[i]!=NULL)
{word[z]=input[i];z++;i++;}word[z]=NULL;
if((strcmp(word,word1))==0)
{if(max1>max2){for(j=0;j<max1-max2;j++)
{for(z=begin;z<=max;z++)
input[z]=input[z+1];
max--;
input[max]=NULL;
}
}
if(max2>max1){for(j=0;j<max2-max1;j++)
{for(z=max;z>=(begin+max1);z--)
input[z+1]=input[z];
max++;
input[max]=NULL;
}
}
z=0;j=0;
for(j=begin;j<begin+max2;j++)
{input[j]=word2[z];z++;}
i=begin+max2;
}
free(word);
}
i++;
}
puts(input);
getche();
free(input);
return 0;
}
Соседние файлы в папке 2