UVA 10815 Andy's First Dictionary (C++ STL map && set )
2024-09-07 13:00:21
原题链接:
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1756
这道题用STL解答还是比较简单的,下面就给大家分享用 set 和 map 的 AC 。
解法一(map):
#include <iostream>
#include <string>
#include <map>
using namespace std;
map<string, char> mmp;
int main(void)
{
int i, idex = 0;
char ch, str[200];
while (ch = getchar()) {
if (ch == EOF) break;
if (isupper(ch)) ch = tolower(ch);
if (islower(ch)) str[idex++] = ch;
else {
str[idex++] = '\0';
if (idex > 1) mmp[str] = 1;
idex = 0;
}
}
for (map<string, char>::iterator i = mmp.begin(); i != mmp.end(); i++)
puts(i -> first.c_str());
return 0;
}
解法二(set):
#include <iostream>
#include <sstream>
#include <string>
#include <set>
using namespace std;
set<string> se;
string x, y;
int main(void)
{
while (cin >> x) {
for (int i = 0; i < x.length(); i++) {
if (isalpha(x[i]))
x[i] = tolower(x[i]);
else x[i] = ' ';
}
stringstream ss(x);//文件流
while (ss >> y) se.insert(y);
}
for (set<string>::iterator it = se.begin(); it != se.end(); it++)
cout << *it << '\n';
return 0;
}
最新文章
- canvas小结
- 体验了微信小程序,发现安卓用户终于把果粉“碾压”了一次
- Winform在线更新
- 数据库 PSU,SPU(CPU),Bundle Patches 和 Patchsets 补丁号码快速参考 (文档 ID 1922396.1)
- Splay伸展树学习笔记
- Alcatraz的安装和使用
- jq tab
- SQL backup&;restore
- TKinter布局之grid 网格布局
- LA 3704 (矩阵快速幂 循环矩阵) Cellular Automaton
- website
- jQuery学习目录
- 【转载】[ORACLE]详解not in与not exists的区别与用法
- 使用SVM对多类多维数据进行分类
- url获取整理
- 一次HTTP请求响应涉及了哪些?
- 小程序支持打开APP
- webvtt字幕转srt字幕的python程序(附改名程序)
- Java拦截器+注解搭配使用
- react-router 从 v2/v3 to v4 迁移(翻译)
热门文章
- <;转>;单机版搭建Hadoop环境
- how2heap libc2.31学习
- Sentinel-Go 源码系列(三)滑动时间窗口算法的工程实现
- MVC三种分页方法
- ftp:500 Illegal PORT command. 425
- C# 金额数字转中文的方法
- FastAPI(六十五)实战开发《在线课程学习系统》基础架构的搭建
- 再谈多线程模型之生产者消费者(多生产者和单一消费者 )(c++11实现)
- 【LeetCode】1020. Partition Array Into Three Parts With Equal Sum 解题报告(Python)
- 【LeetCode】79. Word Search 解题报告(Python & C++)