zoukankan      html  css  js  c++  java
  • CodeForces

    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

    Input
    5 
    birch yellow
    maple red
    birch yellow
    maple yellow
    maple green
    Output
    4
    Input
    3 
    oak yellow
    oak yellow
    oak yellow
    Output
    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=0;i<n;i++)
        {
            string str;
            getline(cin,str);
            m[str]=1;//通过数组下标加入map,也可以用insert函数插入:m.insert(make_pair(str,1));
        }
        int cnt=0;
        for(map<string,int>::iterator it=m.begin();it!=m.end();++it)
        {
            //cout<< it->first<<" "<<it->second<<endl;
            cnt++;
        }
        cout<<cnt<<endl;
        return 0;
    }
  • 相关阅读:
    Myeclipse下使用Maven搭建spring boot项目
    Dubbo+Zookeeper视频教程
    dubbo项目实战代码展示
    流程开发Activiti 与SpringMVC整合实例
    交换两个变量的值,不使用第三个变量的四种法方
    数据库主从一致性架构优化4种方法
    数据库读写分离(aop方式完整实现)
    在本地模拟搭建zookeeper集群环境实例
    box-sizing布局
    盒子模型
  • 原文地址:https://www.cnblogs.com/andrew3/p/8836055.html
Copyright © 2011-2022 走看看