题解 | #Codehorses T-shirts#

Codehorses T-shirts

https://ac.nowcoder.com/acm/problem/112878

掌握SQL后,此题即为入门难度,主要运用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 000 to 333 "X" followed by "S" or "L". For example, sizes "M", "XXS", "L", "XXXL" are valid and "XM", "Z", "XXXXL" are not.

There are nnn 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.

输入描述:

The first line contains one integer nnn (1≤n≤1001 \le n \le 1001n100) — the number of T-shirts.

The iii-th of the next nnn lines contains aia_iai — the size of the iii-th T-shirt of the list for the previous year.

The iii-th of the next nnn lines contains bib_ibi — the size of the iii-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 bbb from the list aaa.

输出描述:

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.
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
map<string, int>temp;
int main()
{
    int n;
    cin >> n;
    int ans = n;
    string s;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        temp[s]++;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        if (temp[s]-- > 0) ans--;
    }
    cout << ans;
    return 0;
}




全部评论

相关推荐

面试摇了我吧:啊哈哈面试提前五个小时发,点击不能参加就是放弃
点赞 评论 收藏
分享
2 收藏 评论
分享
牛客网
牛客企业服务