题目链接:codeforces 44A
5
birch yellow
maple red
birch yellow
maple yellow
maple green
4
3
oak yellow
oak yellow
oak yellow
1
题目大意:每行的开始是一个n,表示一下有 n 行的数据,每行有两个字符串;
目的就是判断除去重复的组还剩余多少组;
AC代码一之map+pair:
 #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
#include<string>
#include<cmath>
#include<map>
using namespace std;
int main()
{
int T,n;
string s1,s2;
map< pair<string,string> ,int >a;
while(cin>>n)
{ int ans = ;
for(int i=; i<n; i++)
{
cin>>s1>>s2;
if(a[make_pair(s1,s2)] == )
{
a[make_pair(s1,s2)]=;
ans++;
}
}
printf("%d\n",ans);
}
return ;
}

AC代码二之map + getline

 #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
#include<string>
#include<cmath>
#include<map>
using namespace std;
map<string ,int >a;
int main()
{
int n;
string s;
while(cin>>n)
{ int ans = ;
getchar();
for(int i=;i<n;i++)
{
getline(cin,s);
if(a[s] == )
{
a[s]=;
ans++;
}
}
printf("%d\n",ans);
}
return ;
}

pair + map 函数结合使用的更多相关文章

  1. map函数(转)

    STL中map用法详解 说明:如果你具备一定的C++ template知识,即使你没有接触过STL,这个文章你也应该可能较轻易的看懂.本人水平有限,不当之处,望大家辅正. 一.Map概述 Map是ST ...

  2. c++之map函数/迭代器

    参考文献:https://www.cnblogs.com/fnlingnzb-learner/p/5833051.html #include <iostream> #include < ...

  3. map 函数----filter函数

    # map 函数 l = (1,2,4,5,6,7,8,9,) print(list(map(lambda x:x**2,l)))#使用list类型((map函数(lambda 匿名函数定义x值:x* ...

  4. 实现python中的map函数

    假设Python没有提供map()函数,自行编写my_map()函数实现与map()相同的功能.以下代码在Python 2.7.8中实现. 实现代码: def my_map(fun,num): i = ...

  5. js parseInt和map函数

    今天看了一个js的题目["1","2","3"].map(parseInt),看到后脑海中浮现的答案是[1,2,3],但是看到正确答案后蒙了 ...

  6. JavaScript中map函数和filter的简单举例(转)

    js的数组迭代器函数map和filter,可以遍历数组时产生新的数组,和python的map函数很类似1)filter是满足条件的留下,是对原数组的过滤:2)map则是对原数组的加工,映射成一一映射的 ...

  7. Python-lambda函数,map函数,filter函数

    lambda函数主要理解: lambda 参数:操作(参数). lambda语句中,冒号前是参数,可以有多个,用逗号隔开,冒号右边的返回值.lambda语句构建的其实是一个函数对象 map函数: ma ...

  8. map() 函数

    map()函数 map()是 Python 内置的高阶函数,它接收一个函数 f 和一个 list,并通过把函数 f 依次作用在 list 的每个元素上,得到一个新的 list 并返回. 例如,对于li ...

  9. STL : map函数的运用 --- hdu 4941 : Magical Forest

    Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

随机推荐

  1. 以下内容为Stackoverflow上整理以作纪录

    PRO 用IMG标签 Use IMG plus alt attribute if the image is part of the content such as a logo or diagram ...

  2. linux环境php将word转换成pdf

    原文地址:http://www.niu12.com/article/15 ubuntu.java环境.openoffice.jodConverter.php 1.安装java环境 a. jdk下载(我 ...

  3. Mybatis数据库操作的返回值

    mybatis配置 <!-- 配置mybatis --> <bean id="sqlSessionFactory" class="org.mybatis ...

  4. Javascript时间字符串比较

    //startdate和enddate的格式为:yyyy-MM-dd hh:mm:ss //当date1在date2之前时,返回1;当date1在date2之后时,返回-1:相等时,返回0 funct ...

  5. linux系统下mysql跳过密码验证登录和创建新用户

    修改MySQL的登录设置: # vi /etc/my.cnf 在[mysqld]的段中加上一句:skip-grant-tables 例如: [mysqld] datadir=/var/lib/mysq ...

  6. 正确遍历删除List中的元素方法(推荐)

    遍历删除List中的元素有很多种方法,当运用不当的时候就会产生问题.下面主要看看以下几种遍历删除List中元素的形式: 1.通过增强的for循环删除符合条件的多个元素 2.通过增强的for循环删除符合 ...

  7. CCPlatformConfig(设置执行平台 iOS android win32等。。。)

    #ifndef __CC_PLATFORM_CONFIG_H__ #define __CC_PLATFORM_CONFIG_H__ /** Config of cocos2d-x project, p ...

  8. Core Data 更新某条指定记录数据

    一:流程 同样需要先查询出指定记录 更新指定记录 二:代码: //更新操作 - (void)updateThePersonData { NSFetchRequest *fetchRequest = [ ...

  9. vue - utils for extract-text-webpack-plugin

    描述:将包或包中的文本提取到单独的文件中, 点击查看官网详情: https://www.npmjs.com/package/extract-text-webpack-plugin

  10. 在k8s上部署第一个php应用

    一.搭建nginx+php 1.站点配置文件 1.1创建nginx-configmap.yaml [root@master k8s]# cat nginx-configmap.yaml apiVers ...