C++ 泛型编程(题库重整)

题目描述

    OJ由于在早期没有题目搜索功能,导致系统内出现了很多重复的题目,为了检查题目重复情况,crq需要统计出系统内哪些题目是重复的,现在就把这个任务交给你了。

输入

     输入数据有多组组,每组数据的第1行是题库总量t,t<=10000。接下来有t行,每行有两个数据,分别为题号(题号从1001开始计直到最后一题,中间没有缺失)和标题(标题是一个字符串,可能包含空格)。

    为简化问题,假设标题长度不超过20个字符,行末没有空格。

    输入以EOF结束。

输出

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<set>
using namespace std;
struct Node
{
	string title;
	int a[10003];
	int c = 1;
	
}t,t1,t2,t3;
bool operator<(Node a,Node b){
	return a.title<b.title;//最小的在最前面
}
set<Node>Set;
set<Node>::iterator it;
int main()
{
	string s;
	int T,x;
	while (scanf("%d", &T) != EOF){

		while (T--)
		{

			cin >> x;
			getchar();
			getline(cin, s);
			t1.title = s;
			t1.a[0] = x;
			if ((it = Set.find(t1)) != Set.end()){
				t = *it;
				Set.erase(it);
				t.a[t.c] = x;
				t.c++;
				Set.insert(t);
			}
			else{
				Set.insert(t1);
			}

		}
		for (it = Set.begin(); it != Set.end(); it++){
			if (it->c != 1){
				t = *it;
				cout << t.title;
				sort(t.a, t.a + t.c);
				for (int i = 0; i <t.c; i++){
					cout << " " << t.a[i];
				}
				cout << endl;
			}
			
		}
		Set.clear();
	}
	
	
	return 0;
}

    请根据标题的字典序输出所有有重复的题目信息,每个信息占一行。

    每行包括一个标题以及所有重复的题号,并按照题号的顺序从小到大排列。之间用空格分开。

样例输入

5
1001 a+b
1003 humble number
1002 humble number
1004 hello world
1005 a+b

样例输出

a+b 1001 1005
humble number 1002 1003

猜你喜欢

转载自blog.csdn.net/A_I_Q/article/details/82905269