游客 Signup | Login
中文 | En

3548 - HTML-1

输入一系列字符串(长度不超过20,字符串个数不超过100),以#号结束,把字符串按照字典序从小到大输出,一个一行

Input

按描述输入

Output

按描述输出

Examples

Input

a b c d    #
() a bb c
ddddddd
#

Output

a
b
c
d
()
a
bb
c
ddddddd

Solution C

#include<stdio.h>
#include<string.h>
void main(){
	unsigned short int i,j=0,k;
	char y[20][100],ch[100];
	while(scanf("%s",y[j++])!=EOF)
	{
		if(strcmp(y[j-1],"#")==0)
		{
			for(i=0;i<j-1;i++)
				for(k=i+1;k<j;k++)
					if(strcmp(y[i],y[k])>0){
						strcpy(ch,y[i]);strcpy(y[i],y[k]);strcpy(y[k],ch);
					}
			for(i=1;i<j;i++)printf("%s\n",y[i]);
			j=0;
		}
	}
}

Solution C++

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
#define ll long long

int cmp(const void *a, const void *b)
{
	char *aa = (char *)a;
	char *bb = (char *)b;
	return strcmp(aa,bb);
}

int main ()
{
	int n, m, i, j, k = 0, len;
	char str[101][21];
	while(scanf("%s",str[k]) != EOF)
	{
		if(strcmp(str[k],"#") == 0)
		{
			qsort(str,k,sizeof(str[0]),cmp);
			for(int i = 0 ; i < k ; i ++)
				printf("%s\n",str[i]);
			k = 0;
		}
		else
			k ++;
	}
	return 0;
}



Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题