задача такая: ввести неизвестное кол-во строк по 100 символов все слова нечётной длинны перевернуть..
| Код | #include "stdafx.h" #include <stdio.h> #include <stdlib.h> #include <conio.h>
int _tmain(int argc, _TCHAR* argv[]) { char **ms, *n,*s, d; int i,j,k,c,kk,l,z; i=j=kk=k=l=0; c=-1; ms=(char**)calloc(2,sizeof(char*)); for(i=0;i<2;i++) ms[i]=(char*)calloc(100,sizeof(char));
printf("vvedite text:\n"); do { if(k>1) { if(!(ms=(char**)realloc(ms,(k+1)*sizeof(char*)))) printf("oshibka"); for(;i<=k;i++) if(!(ms[i]=(char*)calloc(100,sizeof(char)))) printf("oshibka"); }
fgets(ms[k], 99, stdin);
for(j=0;j<100;j++) { if(ms[k][j]=='\n') { ms[k][j]='\0'; break; } }
k++; }while(ms[k-1][0]!='\0');
if(k==1){printf("vi ne vveli ni odnoi stroki\n"); return 0;} for(i=0; i<k;i++) puts(ms[i]);
for(i=0;i<k;i++) { for(j=0;j<100;j++) { kk=1; if(ms[i][j]==' ' || ms[i][j]=='\t' || ms[i][j]=='\0'||ms[i][j]==',' ||ms[i][j]=='.') { l=c; c=-2; kk=0; } c++; if(!kk && !(l%2) && l) { s=(*(ms+i)+j-1); n=s-l; for(z=l/2;z>=0;z--,n++, s--) { d=*s; *s=*n; *n=d; } } } } for(i=0;i<k;i++) puts(ms[i]);
return 0; }
|
вопрос в том, что препод может придраться к решению.. помогите улучшить алгоритм |