改了,已经符合你的要求了#includeusing namespace std;void main(void){ int m=0,n=0,m1,n1; int i; char *p=NULL,*t=NULL; char str[200]="";//临时保存输入的一条字符串 while(1) { m1=m; n1=n;//保存之前的mn scanf("%s",str); if(strcmp(str,"end")==0)break; if(strlen(str)+1>m)m=strlen(str)+1;//确定最长的字符串为宽度 n++;//增加高度 t=(char *)malloc(m*n);//分配 for(i=0;i<n1;i++)memmove(t+i*m,p+i*m1,m1);//移动 memmove(t+i*m,str,m);//把新的加入if(p!=NULL)free(p); p=t; } for(i=0;i<n;i++)cout<<strlen(p+i*m)<<endl; cout<<n<<endl; } |