题干:

先输入你要输入的字符串的个数。然后换行输入该组字符串。每个字符串以回车结束,每个字符串少于一百个字符。如果在输入过程中输入的一个字符串为“stop”,也结束输入。 
然后将这输入的该组字符串按每个字符串的长度,由小到大排序,按排序结果输出字符串。 
Input字符串的个数,以及该组字符串。每个字符串以‘\n’结束。如果输入字符串为“stop”,也结束输入.Output将输入的所有字符串按长度由小到大排序输出(如果有“stop”,不输出“stop”)。 

Sample Input
5
sky is grey
cold
very cold
stop
3
it is good enough to be proud of
good
it is quite good
Sample Output
cold
very cold
sky is grey
good
it is quite good
it is good enough to be proud of
Hint根据输入的字符串个数来动态分配存储空间(采用new()函数)。每个字符串会少于100个字符。 
测试数据有多组,注意使用while()循环输入。


解题报告:

    水题不解释。


ac代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> 
using namespace std;

struct Node {
	char s[100 + 5];
	int len;
} node[100000 + 5];

bool cmp(const Node & a,const Node & b) {
	return a.len<b.len;
	
}
int main()
{
	int n,i;
	int curs;
	while(~scanf("%d",&n) ) {
		curs=0;
		getchar();
		for( i = 0; i<n; i++) {//用到这里的i时,一定要注意了!首先 这里最后多了一个i++,
			gets(node[i].s);	//其次,有stop和没有stop的输入时,要分类讨论,因为如果有stop,因为有break所以没有最后的i++ 
			curs++;
//			printf("curs===%d\n",curs);
			if(!strcmp(node[i].s,"stop")) {
				curs--;
				break;
			}
			node[i].len=strlen(node[i].s);
		}
//		printf("*****curs=%d\n",curs);
		sort(node,node+curs,cmp);
		for(int j = 0; j<curs; j++) {
			printf("%s\n",node[j].s);
		}
		
	}
	
	return 0 ;
 } 

总结:

    暂无