当前位置:网站首页>Application of Andy s first dictionary (uva10815) Purple Book p112set
Application of Andy s first dictionary (uva10815) Purple Book p112set
2022-06-28 20:35:00 【Love_ Jacques】
Purple Book P112;set Application ;Andy’s First Dictionary(UVa10815);
Vjudge Please move the title address here
The main idea of the topic :
Enter a text ( most 500 That's ok , The most in each line 200 Characters , With EOF ending ), Find all the different words , Output in lowercase from small to large in dictionary order ( One word per line ).
Sample Input
Adventures in Disneyland
Two blondes were going to Disneyland when they came to a fork in the
road. The sign read: “Disneyland Left.”
So they went home.
Sample Output
a
adventures
blondes
came
disneyland
fork
going
home
in
left
read
road
sign
so
the
they
to
two
went
were
when
Topic analysis :
data structure choice : Count the words that appear , Of course set;
Algorithm design : Violent simulation , Time O(n) Maximum 100000; Read a string of characters at a time ,for Loop to determine whether a single character is a letter , If converted to lowercase , If it is not , Then save the words formed by the read letters , Start reading the next word again ;
//dict by set aggregate ,s For the currently read string ,now A word consisting of the currently stored letters
if(isalpha(s[i])){
now+=tolower(s[i]);
}else{
if(!now.empty()) dict.insert(now);
now.clear();
}
Module design : Definition and pretreatment – Read in and initialize – Processing strings – Output –return 0;
Code :
#include<iostream>
#include<set>
#include<cctype>
#include<string>
using namespace std;
struct rule{
bool operator()(const string &a,const string &b){
return a<b;
}
};
set<string,rule> dict;
string s;
int main()
{
while(cin>>s)
{
string now;
now.clear();
for(int i=0;i<s.length();i++)
{
if(isalpha(s[i])){
now+=tolower(s[i]);
}else{
if(!now.empty()) dict.insert(now);
now.clear();
}
}
if(!now.empty()) dict.insert(now);
}
for(set<string>::iterator i=dict.begin();i!=dict.end();i++)//auto i=dict.begin();
cout<<*i<<endl;
return 0;
}
Summary of key points and details :
- The code uses a string handler
isalpha()Andtolower();isalpha(): Decide if it's a letter ;islower(): Decide if it's lowercase ;isupper(): Decide if it's capital ;tolower(): Convert to lowercase ;toupper(): Convert to uppercase ; - set Insertion
insert()If a duplicate value is encountered, it is invalid ; - Code for now Can be replaced by an input stream : Non alphabetic conversion to space encountered , And then to s Stream input processing , Header file required
#include<sstream>;
for(int i=0;i<s.length();i++)
if(isalpha(s[i])) s[i]=tolower(s[i]); else s[i]=' ';
stringstream ss(s);
while(ss>>buf) dict.insert(buf);
- Define iterators in your code
set<string>::iterator i=dict.begin();You can use more conciseauto i=dict.begin()Replace .
Update and 2020.6.23
边栏推荐
- 03.hello_rust
- 应用实践 | 10 亿数据秒级关联,货拉拉基于 Apache Doris 的 OLAP 体系演进(附 PPT 下载)
- 请问同业存单是否靠谱,安全吗
- APISIX 助力中东社交软件,实现本地化部署
- API gateway Apache APIs IX helps the evolution of snowball dual active architecture
- Characters and integers
- Comparisonchain file name sort
- Lecture 30 linear algebra Lecture 4 linear equations
- How to analyze the relationship between enterprise digital transformation and data asset management?
- openGauss内核分析之查询重写
猜你喜欢
![[graduation season · advanced technology Er] hard work can only pass, hard work can be excellent!](/img/e5/b6035abfa7d4bb59c3080d3b87ce45.jpg)
[graduation season · advanced technology Er] hard work can only pass, hard work can be excellent!

2022茶艺师(中级)考试模拟100题及模拟考试

Automatic operation and maintenance platform based on Apache APIs

Rsync remote synchronization

ref属性,props配置,mixin混入,插件,scoped样式

UESTC (shenhengtao team) & JD AI (Mei Tao team) proposed a structured dual stream attention network for video Q & A, with performance SOTA! Better than the method based on dual video representation

RT thread thread synchronization and thread communication

Racher add / delete node

Win 10 create a gin framework project

Visualization of neural network structure in different frames
随机推荐
Analysis of all knowledge points of TCP protocol in network planning
Leetcode 36. 有效的数独(可以,一次过)
阿里云 MSE 基于 Apache APISIX 的全链路灰度方案实践
Various types of long
[learning notes] cluster analysis
开通挖财账号安全吗?是靠谱的吗?
2022茶艺师(中级)考试模拟100题及模拟考试
Comparisonchain file name sort
2022 tea master (intermediate) examination simulated 100 questions and simulated examination
API gateway Apache APIs IX helps the evolution of snowball dual active architecture
T检验(检验两个总体的均值差异是否显著)
C # connect to the database to complete the operation of adding, deleting, modifying and querying
Explanation of memory dump triggered by software watchdog and anr
题解 The Blocks Problem(UVa101)紫书P110vector的应用
The principle and source code analysis of Lucene index construction
How to understand the usability of cloud native databases?
Analysis of variance
输入分隔符
UESTC (shenhengtao team) & JD AI (Mei Tao team) proposed a structured dual stream attention network for video Q & A, with performance SOTA! Better than the method based on dual video representation
RT-Thread线程同步与线程通信