2020.03.06 A题解

A - Codehorses T-shirts

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 0 to 3 “X” followed by “S” or “L”. For example, sizes “M”, “XXS”, “L”, “XXXL” are valid and “XM”, “Z”, “XXXXL” are not.

There are n 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 n (1≤n≤100) — the number of T-shirts.

The i-th of the next n lines contains ai — the size of the i-th T-shirt of the list for the previous year.

The i-th of the next n lines contains bi — the size of the i-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 b from the list a.

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.

题意: 输入一个整数n,紧接着n行输入T恤目前的码号,接下来n行输入所需T恤的码号。问至少换几次,能够得到上下相同的n组序列,使T恤的码号符合要求(没有顺序)

思路: 定义string数组,存放输入的2*n组码号。定义一个计时器count计相同的组数,从上面的n行开始一一与下面n行的字符串比较,相同则count++,此时将下面原本的字符串修改初始值(即避免重复),最后n和count的值之差即不同的组数需要更换。

#include <bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')
		w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*w;
}
int main(){
	int n=read();
	int count=0;
	string s[1000];
	for(int i=0;i<2*n;i++){
		cin>>s[i];
	}
	for(int i=0;i<n;i++){
		for(int k=n;k<2*n;k++){
			if(s[i]==s[k]){
				s[k]='0';
				count++;
				break;
			}
		}
	}
	cout<<n-count<<endl;
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值