CodeForces 637B Chat Order

本文介绍了一个简单的算法,用于模拟社交网络中聊天列表的管理。当发送消息给某位朋友时,该聊天会升至列表顶部;若为新聊天,则插入到顶部。通过使用C++实现,并借助map来标记已处理的聊天记录,确保每个聊天只被输出一次。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

思路:水题..其实就是把输入的字符串倒着输出就行了,加个map判重就可以了


#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <ctime>
#include <cmath>
#include <cctype>
using namespace std;
#define maxn 200005
#define LL long long
int cas=1,T;
map<string,int> visit;
string s[maxn];
int main()
{
	int n;
	while (scanf("%d",&n)!=EOF)
	{
		for (int i = 0;i<n;i++)
		{
			cin >> s[i];
	        //visit[s[i]]=1;		
		}
		for (int i = n-1;i>=0;i--)
		{
			if (!visit[s[i]])
				cout << s[i] << endl;
			visit[s[i]]=1;
		}
	}
	//freopen("in","r",stdin);
	//scanf("%d",&T);
	//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}

Description

Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.

Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.

Input

The first line contains integer n (1 ≤ n ≤ 200 000) — the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.

Output

Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.

Sample Input

Input
4
alex
ivan
roman
ivan
Output
ivan
roman
alex
Input
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
Output
alina
maria
ekaterina
darya


### Chat2DB与Navicat功能对比及特点 #### 功能对比 Navicat是一款成熟的商业数据库管理工具,以其稳定性、安全性和丰富的功能而闻名。它提供了直观的图形化用户界面以及多种高级特性,如数据同步、结构同步和自动化任务调度等功能[^1]。 相比之下,Chat2DB作为一款新兴的开源数据库管理工具,不仅具备传统数据库客户端的核心功能,还引入了人工智能技术(AIGC),使其能够在自然语言处理方面表现出色。例如,它可以将自然语言转化为SQL语句,反之亦然;同时还能提供SQL性能优化建议,从而显著提高用户的生产力[^2]。 #### 技术特点 Navicat的技术特点是基于多年的经验积累,专注于为企业级用户提供可靠的解决方案。它的主要优势在于跨平台兼容性、高度的安全保障机制以及针对复杂操作的支持能力。 另一方面,Chat2DB的特点则体现在其创新性的AI集成上。除了常规的数据管理和查询外,该工具有助于降低非技术人员学习成本,允许不懂SQL的人也能轻松完成日常数据分析工作。此外,Chat2DB还可以帮助解决因不同数据库之间存在的语法差异带来的挑战,比如实现MySQL到Oracle或其他类型的SQL转换[^4]。 #### 用户体验 就用户体验而言,Navicat设计了一个非常友好且易于导航的操作环境,这使得即使是初学者也能够迅速掌握如何有效利用这款软件来执行各种各样的数据库活动。 对于那些寻求更智能化交互方式的人来说,Chat2DB可能更加吸引他们注意。由于内置了先进的算法模型,所以即便是在面对复杂的业务场景时,也可以借助简单的文字描述获得所需的结果或者指导[^3]。 ```sql -- MySQL分页查询示例 SELECT s.name, SUM(sc.score) AS total_score FROM student s INNER JOIN student_course sc ON s.id = sc.student_id GROUP BY s.id ORDER BY total_score DESC LIMIT 10; -- Oracle对应的分页查询写法 SELECT s.name, SUM(sc.score) AS total_score FROM student s INNER JOIN student_course sc ON s.id = sc.student_id GROUP BY s.id, s.name ORDER BY total_score DESC FETCH FIRST 10 ROWS ONLY; ``` 以上展示了两个不同的数据库系统之间的SQL语句转换实例,进一步体现了Chat2DB在这方面的实用价值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值