Andy's First Dictionary

Andy's First Dictionary

SCUACM2022集训前训练-数据结构 - Virtual Judge (vjudge.net)

stringstream

把单词从字符串里分离出来,可以先把字符串里的非字母字符变成 空格, 再放入 stringstream 中,再读 stringstream 这样单词就被分离出来了

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <sstream>
using namespace std;
typedef long long ll;

set<string> st;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	string s;
	while(cin >> s)
	{
		for (int i = 0; i < s.size(); i++)
		{
			if (isalpha(s[i]))
				s[i] = tolower(s[i]);
			else
				s[i] = ' ';
		}
		stringstream ss(s);
		while(ss >> s)
			st.insert(s);
	}
	for (auto str : st)
		cout << str << endl;
	return 0;
}

posted @   hzy0227  阅读(27)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
· 零经验选手,Compose 一天开发一款小游戏!
点击右上角即可分享
微信分享提示