⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2142071_ac_0ms_56k.cpp

📁 北大大牛代码 1240道题的原代码 超级权威
💻 CPP
字号:
# include <stdio.h>
# include <string.h>
# include <algorithm>

struct node
{
	char s[20];
}num[100], str[100];

bool cmp1(struct node a,struct node b)
{
	if(a.s[0]=='-')
	{
		if(b.s[0]=='-')
			if(strlen(a.s)!=strlen(b.s))
				return strlen(a.s)>strlen(b.s);
			else
				return strcmp(a.s,b.s)>0;
		else
			return 1;
	}
	else
	{
		if(b.s[0]=='-')
			return 0;
		else
			if(strlen(a.s)!=strlen(b.s))
				return strlen(a.s)<strlen(b.s);
			else
				return strcmp(a.s,b.s)<0;
	}
}

bool cmp2(struct node a,struct node b)
{
	char ta[20], tb[20];

	strcpy(ta,a.s);
	strcpy(tb,b.s);
	for(int i = 0; ta[i]!='\0'; i++)
		if(ta[i]<'a')
			ta[i] += 32;
	for(i = 0; tb[i]!='\0'; i++)
		if(tb[i]<'a')
			tb[i] += 32;
	return strcmp(ta,tb)<0;
}

void input()
{
	int n, s, l;
	bool mark;
	bool flag[200];
	char tmp[20];

	while(scanf("%s",tmp)==1&&strcmp(tmp,".")!=0)
	{
		n = s = 0;
		mark = 1;
		memset(flag,0,sizeof(flag));
		if(tmp[strlen(tmp)-1]=='.')
			puts(tmp);
		else
		{
			int i;

			i = 0;
			while(mark)
			{
				if(tmp[strlen(tmp)-1]=='.')
					mark = 0;
				tmp[strlen(tmp)-1] = '\0';
				if((tmp[0]>='0'&&tmp[0]<='9')||tmp[0]=='-')
					strcpy(num[n++].s,tmp);
				else
				{
					flag[i] = 1;
					strcpy(str[s++].s,tmp);
				}
				i++;
				if(mark)
					scanf("%s",tmp);
			}
			std::sort(num,num+n,cmp1);
			std::sort(str,str+s,cmp2);
			l = n + s;
			n = s = 0;
			for(i = 0; i < l; i++)
			{
				if(flag[i])
					printf("%s",str[s++].s);
				else
					printf("%s",num[n++].s);
				if(i==l-1)
					printf(".\n");
				else
					printf(", ");
			}
		}
	}
}

int main()
{
	input();
	return 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -