码迷,mamicode.com
首页 > 其他好文 > 详细

1039 到底买不买

时间:2020-02-19 13:09:29      阅读:62      评论:0      收藏:0      [点我收藏+]

标签:ima   个数   表示   lse   pac   ble   class   nbsp   color   

较水。

#include<iostream>
using namespace std;

int hashtable1[300] = {0},hashtable2[300]= {0};
int main() {
    string str1,str2;
    cin>>str1>>str2;
    for(int i = 0; i < str1.size(); ++i)
        hashtable1[str1[i]]++;
    for(int i = 0; i < str2.size(); ++i)
        hashtable2[str2[i]]++;
    int cnt1 = 0,cnt2 = 0;//分别表示多余的珠子和欠缺的珠子的总个数
    for(int i = 0; i < 300; ++i) { //遍历两个hashtable 
        if(hashtable1[i] >= hashtable2[i]) cnt1 += hashtable1[i] - hashtable2[i];
        else cnt2 += hashtable2[i] - hashtable1[i];
    }
    if(cnt2 != 0) printf("No %d",cnt2);
    else printf("Yes %d",cnt1);
    return 0;
}

技术图片

 

1039 到底买不买

标签:ima   个数   表示   lse   pac   ble   class   nbsp   color   

原文地址:https://www.cnblogs.com/keep23456/p/12330675.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!