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

📄 1081.cpp

📁 这是哈尔滨工业大学acmOJ的源代码
💻 CPP
字号:
/*  This Code is Submitted by wywcgs for Problem 1081 on 2006-01-06 at 23:41:47 */ 
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <algorithm>
using namespace std;

const int MAX = 128;

int wcmp(const void*, const void*);

int main()
{
	bool isw[MAX];
	char word[MAX][16];
	int num[MAX], i;
	
	while(true) {
		char ch = getchar();
		if(ch == '.') break;
		else ungetc(ch, stdin);
		int tn = 0, nn = 0, wn = 0;
		while(ch != '.') {
			ch = getchar();
			isw[tn] = isalpha(ch);
			ungetc(ch, stdin);
			if(isw[tn++]) scanf("%[a-zA-Z]", word[wn++]);
			else scanf("%d", &num[nn++]);
			scanf("%c\n", &ch);
		}
		sort(num, num+nn);
		qsort(word, wn, sizeof(word[0]), wcmp);
		int wh = 0, nh = 0;
		for(i = 0; i < tn; i++) {
			if(isw[i]) printf("%s", word[wh++]);
			else printf("%d", num[nh++]);
			if(i == tn-1) printf(".\n");
			else printf(", ");
		}
	}
	
	return 0;
}

int wcmp(const void* a, const void* b)
{
	char x[16], y[16];
	strcpy(x, (char*)a); strcpy(y, (char*)b);
	int i;
	for(i = 0; i < 16; i++) {
		if(isupper(x[i])) x[i] -= 'A' - 'a';
		if(isupper(y[i])) y[i] -= 'A' - 'a';
	}
	return strcmp(x, y);
}

⌨️ 快捷键说明

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