YTU 2774: Prepare for CET6
2774: Prepare for CET6
时间限制: 1 Sec 内存限制: 128 MB
提交: 40 解决: 37
题目描述
Hard to force the CET4&6 is imminent, which makes most of the students a headache. This does not, Liu is trying his best to prepare for the CET6, trying to do a variety of previous year’s problem. But the most helpless for Liu is a quick read of this topic,
so he thought of a thing does not make sense is that the statistical article the total number in different words. Here your task is to help Liu solve this problem.
输入
Multiple sets of data, each row is an article. Each article is consisted by lowercase letters and spaces, no punctuation, encounter # when the input end.
输出
Each group output only an integer, which alone make the trip, the integer representing the total number of different words in an article.
样例输入
you are my friend
can you can a can as a canner can can a can
#
样例输出
4
5
提示
c++ stl集合(Set)是一种包含已排序对象的关联容器。set会根据待定的排序准则,自动将元素排序,不允许元素重复。
1) 不能直接改变元素值,因为那样会打乱原本正确的顺序,要改变元素值必须先删除旧元素,则插入新元素
2) 不提供直接存取元素的任何操作函数,只能通过迭代器进行间接存取,而且从迭代器角度来看,元素值是常数
3) 元素比较动作只能用于型别相同的容器(即元素和排序准则必须相同)
set模板原型://Key为元素(键值)类型
template <class Key, class Compare=less<Key>, class Alloc=STL_DEFAULT_ALLOCATOR(Key) >
添加元素
set<string> set1;
//empty set
set1.insert("the");
//set1 now has one element
set1.insert("and");
//set1 now has two elements
c++ stl容器set成员函数:
size()--集合中元素的数目
C++引入了ostringstream、istringstream、stringstream这三个类,要使用他们创建对象就必须包含<sstream>这个头文件。
istringstream类用于执行C++风格的串流的输入操作。
ostringstream类用于执行C风格的串流的输出操作。
strstream类同时可以支持C风格的串流的输入输出操作。
istringstream的构造函数原形如下:
istringstream::istringstream(string str);
它的作用是从string对象str中读取字符。
#include<iostream>
#include<sstream>
using namespace std;
int main()
{
string str, line;
while(getline(cin, line))
{
istringstream stream(line);
while(stream>>str)
cout<<str.c_str()<<endl;
}
return 0;
}
测试:
Input:
Abdc Xcs Xa Xa
Output:
Abdc
Xcs
Xa
你 离 开 了 , 我 的 世 界 里 只 剩 下 雨 。 。 。
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
string s;
char t;
while(getline(cin,s)&&s!="#")
{
string p[1000];
int len=s.length(),i=0,count=0,k=0,con;
while(i<len)
{
while(s[i]!=' '&&i<len)t=s[i++],p[count]+=t;
++count,i++;
}
sort(p,p+count);
con=count;
for(i=1; i<count; ++i)
{
k=0;
while(p[i]==p[i-1])k++,i++;
con-=k;
}
cout<<con<<'\12';
}
return 0;
}
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
string s;
char t;
while(getline(cin,s)&&s!="#")
{
string p[1000];
int len=s.length(),i=0,count=0,k=0,con;
while(i<len)
{
while(s[i]!=' '&&i<len)t=s[i++],p[count]+=t;
++count,i++;
}
sort(p,p+count);
con=count;
for(i=1; i<count; ++i)
{
k=0;
while(p[i]==p[i-1])k++,i++;
con-=k;
}
cout<<con<<'\12';
}
return 0;
}
YTU 2774: Prepare for CET6的更多相关文章
- HDOJ(HDU) 2135 Rolling table
Problem Description After the 32nd ACM/ICPC regional contest, Wiskey is beginning to prepare for CET ...
- HDU 2135 Rolling table
http://acm.hdu.edu.cn/showproblem.php?pid=2135 Problem Description After the 32nd ACM/ICPC regional ...
- Looper.prepare()和Looper.loop()
什么时候需要 Looper Looper用于封装了android线程中的消息循环,默认情况下一个线程是不存在消息循环(message loop)的,需要调用Looper.prepare()来给线程创建 ...
- java.lang.NoSuchMethodException: org.apache.ibatis.executor.statement.StatementHandler.prepare(java.sql.Connection)
此错误是由于版本造成的,如果使用mybatis3.4版本以上,配置拦截器规则应增加Intger @Intercepts({ @Signature( type= StatementHandler.cla ...
- ytu 1057: 输入两个整数,求他们相除的余数(带参的宏 + 模板函数 练习)
1057: 输入两个整数,求他们相除的余数 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 177 Solved: 136[Submit][Status ...
- poj 2774
传送门:http://poj.org/problem?id=2774 裸的后缀数组,我只是为了贴个版而已 代码 #include <cstdio> #include <cmath&g ...
- php+mysql预查询prepare 与普通查询的性能对比
prepare可以解决大访问量的网站给数据库服务器所带来的负载和开销,本文章通过实例向大家介绍预查询prepare与普通查询的性能对比,需要的朋友可以参考一下. 实例代码如下: <?php cl ...
- 在子线程中new Handler报错--Can't create handler inside thread that has not called Looper.prepare()
在子线程中new一个Handler为什么会报以下错误? java.lang.RuntimeException: Can't create handler inside thread that has ...
- PerconaXtraBackup --全备增备prepare restore
Xtrabackup Xtrabackup包含两个主要的工具,即xtrabackup和innobackupex,二者区别如下: • xtrabackup只能备份innodb和xtradb引擎表,而不 ...
随机推荐
- swift Enumerations
swift Enumerations enum.case.switch CaseIterable allCases 要区别枚举变量和关联值 枚举变量参与枚举运算: 关联值和rawvalue不参与. A ...
- BZOJ 3884: 上帝与集合的正确用法 扩展欧拉定理 + 快速幂
Code: #include<bits/stdc++.h> #define maxn 10000004 #define ll long long using namespace std; ...
- Oracle XE WM_CONCAT undifine
用docker 跑了个oracle XE 报错 没有WM_CONCAT 下载三个sql文件然后按顺序执行后可以正常使用 一:下载三个文件 解压到 oracle 目录下面 (要能找到,注意权限要o ...
- 基于APE物理引擎的管线容积率计算方法
容积率一般应用在房地产开发中,是指用地范围内地上总建筑面积与项目总用地面积的比值,这个参数是衡量建设用地使用强度的一项非常重要的指标.在其他行业,容积率的计算也非常重要,如产品利用率.管道使用率等等. ...
- C++ Primer(第4版)-学习笔记-第5部分:高级主题
第17章 用于大型程序的工具 异常处理 不存在数组或函数类型的异常.相反,如果抛出一个数组,被抛出的对象转换为指向数组首元素的指针,类似地,如果抛出一个函数,函数被转换为指向该函数的指针. 不要抛出 ...
- anaconda镜像
下载一个包老是下载不下来,于是放弃了官方版改为国内镜像. 清华镜像 (打开Anaconda Prompt 或者 打开cmd,运行下面的命令) conda config --add channels ...
- Cash Machine POJ - 1276
解法 多重背包板子题 多重背包板子 如果上限的体积大于了给定的体积那么套完全背包 否则二进制优化成01背包 代码 #include <iostream> #include <cstr ...
- The content of element type "resultMap" must match ...
mybatis中的mapper文件错误 ①错误原因: <resultMap>标签中需要按照一下顺序编写: <id> <result> <association ...
- 洛谷 2922 BZOJ 1590 [USACO08DEC]秘密消息Secret Message
[题意概述] 给出n个01串组成的字典和m个询问,每次询问某个01串和多少个字典中的串有相同的前缀.(前缀长度是两串中较小的部分) [题解] 直接上Trie树即可.树上每个节点记录两个信息:这个节点有 ...
- 在centos7中使用yum安装mysql数据库并使用navicat连接
1.安装 1.查看yum列表,发现没有mysql [root@server-mysql src]# yum list mysql 已加载插件:fastestmirror Repodata is ove ...