【YBTOJ】生日相同

题目大意:

给你几个人的名字和他们的生日,求生日相同的人的生日和他们的名字。

正文:

对于每个生日开一个 \(\texttt{vector}\),我开到了 \(\texttt{1231}\),如果足够聪明可能可以只开到 \(\texttt{366}\)

代码:


inline ll READ()
{
	ll x = 0, f = 1;
	char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = -f, c = getchar();
	while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar();
	return x * f;
}

int n;
bool flag = 1;
vector <string> a[1300];

bool cmp(string a, string b)
{
	int as = a.size(), bs = b.size();
	if (as == bs) return a < b;
	return as < bs;
}

int main()
{
	n = READ();
	for (int i = 1; i <= n; i++)
	{
		string s; int x;
		cin >> s;
		x = READ() * 100 + READ();
		if (!a[x].empty()) flag = 0;
		a[x].push_back(s); 
	}
	if (flag) {puts("None"); return 0;} 
	for (int i = 101; i <= 1231; i++)
		if (!a[i].empty())
		{
			printf ("%d %d ", i / 100, i % 100);
			sort (a[i].begin(), a[i].end(), cmp);
			for (int j = 0; j < a[i].size(); j++)
				cout << a[i][j] << ' ';
			putchar(10);
		}
	return 0;
}

posted @ 2021-04-29 13:52  Jayun  阅读(77)  评论(0编辑  收藏  举报