Codehorses T-shirts (map+遍历)
Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organizers are giving T-shirts for the winners.
The valid sizes of T-shirts are either "M" or from 00 to 33 "X" followed by "S" or "L". For example, sizes "M", "XXS", "L", "XXXL" are valid and "XM", "Z", "XXXXL" are not.
There are nn winners to the cup for both the previous year and the current year. Ksenia has a list with the T-shirt sizes printed for the last year cup and is yet to send the new list to the printing office.
Organizers want to distribute the prizes as soon as possible, so now Ksenia is required not to write the whole list from the scratch but just make some changes to the list of the previous year. In one second she can choose arbitrary position in any word and replace its character with some uppercase Latin letter. Ksenia can't remove or add letters in any of the words.
What is the minimal number of seconds Ksenia is required to spend to change the last year list to the current one?
The lists are unordered. That means, two lists are considered equal if and only if the number of occurrences of any string is the same in both lists.
Input
The first line contains one integer nn (1≤n≤1001≤n≤100) — the number of T-shirts.
The ii-th of the next nn lines contains aiai — the size of the ii-th T-shirt of the list for the previous year.
The ii-th of the next nn lines contains bibi — the size of the ii-th T-shirt of the list for the current year.
It is guaranteed that all the sizes in the input are valid. It is also guaranteed that Ksenia can produce list bb from the list aa.
Output
Print the minimal number of seconds Ksenia is required to spend to change the last year list to the current one. If the lists are already equal, print 0.
Examples
Input
3
XS
XS
M
XL
S
XS
Output
2
Input
2
XXXL
XXL
XXL
XXXS
Output
1
Input
2
M
XS
XS
M
Output
0
Note
In the first example Ksenia can replace "M" with "S" and "S" in one of the occurrences of "XS" with "L".
In the second example Ksenia should replace "L" in "XXXL" with "S".
In the third example lists are equal.
题解:题目的意思是找出不一样的换掉,并且换的次数最少
map+遍历
代码:
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
const int N = 105;
string a[N],b[N];
map<string,int>A,B;
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++)
cin>>b[i];
for(int i=0;i<n;i++){
A[a[i]]++;
B[b[i]]++;
}
map<string,int>::iterator it;
int ans=n;
for(it=A.begin();it!=A.end();it++)
ans-=min(it->second,B[it->first]);
cout<<ans<<endl;
return 0;
}
Codehorses T-shirts (map+遍历)的更多相关文章
- 分页查询和分页缓存查询,List<Map<String, Object>>遍历和Map遍历
分页查询 String sql = "返回所有符合条件记录的待分页SQL语句"; int start = (page - 1) * limit + 1; int end = pag ...
- js中三个对数组操作的函数 indexOf()方法 filter筛选 forEach遍历 map遍历
indexOf()方法 indexOf()方法返回在该数组中第一个找到的元素位置,如果它不存在则返回-1. 不使用indexOf时 var arr = ['apple','orange','pea ...
- map遍历的四种方式
原文 http://blog.csdn.net/dayanxuqun/article/details/26348277 以下是map遍历的四种方式: // 一.推荐只用value的时候用,都懂的... ...
- 原生JS forEach()和map()遍历的区别以及兼容写法
一.原生JS forEach()和map()遍历 共同点: 1.都是循环遍历数组中的每一项. 2.forEach() 和 map() 里面每一次执行匿名函数都支持3个参数:数组中的当前项item,当前 ...
- map遍历性能记录
map遍历可以通过keySet或者entrySet方式. 性能上:entrySet略胜一筹,原因是keySet获取到key后再根据key去获取value,在查一遍,所以慢一些. keySet: //先 ...
- forEach() 和 map() 遍历
1.forEach() 没有返回值. arr[].forEach(function(value,index,array){ //do something }) 参数:value数组中的当前项, i ...
- js的map遍历和array遍历
1. array遍历: [1].forEach() forEach是ES5中操作数组的一种方法,主要功能是遍历数组.forEach方法中的function回调有三个参数:第一个参数是遍历的数组内容,第 ...
- react.js map遍历的问题
React遍历多个Ant Design中的Upload组件时,随意删除任一个Upload出现了bug,依次点击上传图片后,当点击删除时,倒着删除没有问题,从中间和从开头删问题出现了,出现了类似塌方的效 ...
- map遍历的几种方式和效率问题
一.map遍历的效率 先创建一个map,添加好数据: Map<String, String> map = new HashMap<>();for (int i = 0; i & ...
随机推荐
- requests上传文件,又要上传data的处理
前话 最近在自己学着弄接口自动化框架,因为要封装一个发送请求的父类,其中有考虑到上传文件,以及同时上传文件,和传递其他字段数据,遇到点小问题 这里解决下. 实例的接口数据 参考文档 来自fastapi ...
- python8.3多进程
from multiprocessing import Processimport time def run1 (name,sex): print(name,sex,"执行进程1" ...
- 2020-04-06:insert语句在mysql里经历了什么?
1.会话状态转换为update 2.激活事物状态由 not_active 变为 active 3.查找定位数据 4.进行乐观插入 记录insert的undo记录记录undo的redo log 入red ...
- JavaScript Object初始化的不同方式
不带原型的对象,纯对象 const plaintObject = Object.create(null) 带原型的对象 const originObject = new Object()
- Homekit_Dohome_智能灯带
简介:本款产品支持音乐律动控制,可以随音乐改换颜色及频率,可以使用Homekit或者Dohome或者遥控器进行有效控制,同时Dohome App已经对接了各大智能音箱,下载Dohome App后就可以 ...
- flask-migrate 处理sqlite数据库报错Constraint must have a name 的解决方案
环境:flask+python+sqlite,我想给某个表里某个字段加unique属性 执行 python manage.py db migrate 没报错,执行 python manage.py d ...
- 数据库之Oracle优化技巧(一)
数据库之Oracle优化技巧(一) 1.where子句中的连接顺序 在Oracle数据库中,where子句的执行顺序是自下而上进行解析,根据这个原理,表之间的连接必须写在其他where条件之前,那些可 ...
- 【CQOI2018】异或序列 - 莫队
题目描述 已知一个长度为n的整数数列 $a_1,a_2,...,a_n$,给定查询参数l.r,问在 $a_l,a_{l+1},...,a_r$ 区间内,有多少子序列满足异或和等于k.也就是说,对于 ...
- unity探索者之socket传输protobuf字节流(四)
版权声明:本文为原创文章,转载请声明http://www.cnblogs.com/unityExplorer/p/7027659.html 上篇已经把socket的传输说的差不多了,这篇主要是说说断线 ...
- 第1章 RDD概念 弹性分布式数据集
第1章 RDD概念 弹性分布式数据集 1.1 RDD为什么会产生 RDD是Spark的基石,是实现Spark数据处理的核心抽象.那么RDD为什么会产生呢? Hadoop的MapReduce是一种基于 ...