CodeForces - 44A Indian Summer
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.
Input
The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.
Output
Output the single number — the number of Alyona's leaves.
Examples
5
birch yellow
maple red
birch yellow
maple yellow
maple green
4
3
oak yellow
oak yellow
oak yellow
1
这个map很快的,map的键不允许重复,所以有重复的直接过滤了,把两个字符串加起来达到合并的效果,然后插入map,再计算个数就行了
#include <map>
#include <string>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
map<string,int> m; int main()
{
int n;
cin>>n;
getchar();
for(int i=;i<n;i++)
{
string str;
getline(cin,str);
m[str]=;//通过数组下标加入map,也可以用insert函数插入:m.insert(make_pair(str,1));
}
int cnt=;
for(map<string,int>::iterator it=m.begin();it!=m.end();++it)
{
//cout<< it->first<<" "<<it->second<<endl;
cnt++;
}
cout<<cnt<<endl;
return ;
}
CodeForces - 44A Indian Summer的更多相关文章
- pair + map 函数结合使用
题目链接:codeforces 44A5birch yellowmaple redbirch yellowmaple yellowmaple green 4 3oak yellowoak yellow ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- hive的体系架构及安装
1,什么是Hive? Hive是能够用类SQL的方式操作HDFS里面数据一个数据仓库的框架,这个类SQL我们称之为HQL(Hive Query Language) 2,什么是数据仓库? 存放数据的地方 ...
- RPC-Thrift(四)
Client Thrift客户端有两种:同步客户端和异步客户端. 同步客户端 同步客户端比较简单,以RPC-Thrift(一)中的的例子为基础进行研究源码,先看一下类图. TServiceClient ...
- 【BZOJ】1596: [Usaco2008 Jan]电话网络
[算法]树上贪心 [题解] 因为一个点必须被覆盖,那么它如果没有被子树节点覆盖的话,就覆盖它的父节点. 从叶子开始贪心. 注意,如果它自己已经被选了就不需要选父节点了. #include<cst ...
- andriod开发增加一个菜单
第一步: E:\01.prj\pyscrapy\Cet4\res\menu\main.xml <menu xmlns:android="http://schemas.android ...
- UVALIVE 3891 The Teacher's Side of Math
One of the tasks students routinely carry out in their mathematics classes is to solve a polynomial ...
- pm2笔记
概述 pm2是一个进程管理工具.使用pm2部署NodeJS服务可以轻松实现负载均衡. 指定用户启动 pm2启动时会指定一个PM2_HOME目录,作为存放日志文件.rpc.sock文件,默认情况下会PM ...
- 网络编程学习笔记--1.socket可读可写条件
转至 :http://blog.csdn.net/majianfei1023/article/details/45788591 socket可读可写条件,经常做为面试题被问,因为它考察被面试者对网络编 ...
- testng+IEDriverServer+yum+tomcat下载软件包
testng框架链接:http://files.cnblogs.com/files/linxinmeng/testng%EF%BC%88selenium%E6%A1%86%E6%9E%B6%EF%BC ...
- shipyard, swarm看到你,我才睡觉:)
windows下用boot2docker有点不爽,就是网卡识别不好. 还是用纯的virtualbox建centos7虚拟机来搞, 一下就OK. 但记得,要用Iptables来弄墙,去掉firewall ...
- (一)Centos7安装zabbix3.4 server端
(1)环境准备 关闭firewalld和selinux systemctl stop firewalld systemctl disable firewalld #sed -ri '/^SELINUX ...