【map<s,i>&getline】#STC 2 A. Indian Summer

A. Indian Summer
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 nlines 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 10lowercase 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.

Sample test(s)
input
5
birch yellow
maple red
birch yellow
maple yellow
maple green
output
4
input
3
oak yellow
oak yellow
oak yellow
output
1


这道题和#42一样用map<string,int>就会很方便呢~但是这里很狡猾,给你的东西里有空格分开,那么怎么办呢?~

1) string相加,直接加起来是字符串合并的效果

2)getline:getline(cin,str); //cin:输入流;str:string对象getline函数从输入流的下一行读取,并保存读取的内容到str中,但不包括换行符

接下来就是一样的map偷懒Code:

#include <map> 
#include <queue>
#include <cmath> 
#include <memory> 
#include <cctype>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
map<string,int> m;

int main()
{
	int n;	cin>>n;
	char c; scanf("%c",&c);
	for(int i=0;i<n;i++)
	{
		string str;
		getline(cin,str);
		m[str]=1;
	}
	int cnt=0;
	for(map<string,int>::iterator it=m.begin();it!=m.end();++it)
	{
		//cout<< it->first<<endl;
		cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

糖果天王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值