Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
DallasAutumn committed Mar 1, 2020
1 parent cb6c0c0 commit 14f3df4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions A1092.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# A1092 To Buy or Not to Buy

## 1.题意理解
给出两个串,第一个是提供的,第二个是需要的,要求判断供给是否能满足需求,若能满足多多少,不能满足差多少。

## 2.题目分析
直接把串中每个字符的个数统计起来即可,可以视作hash的应用,使用map简单实现

## 3.参考代码
```cpp
#include <bits/stdc++.h>
using namespace std;

const int MAXL = 1024;

map<char, int> mp;

int main()
{
string buy, want;
int extra = 0, miss = 0;
bool flag = true;
cin >> buy;
cin >> want;
for (char c : buy)
mp[c]++;
for (char c : want)
{
if (!mp[c])
{
flag = false;
miss++;
}
else
mp[c]--;
}
if (flag)
{
for (auto it : mp)
extra += it.second;
printf("Yes %d\n", extra);
}
else
printf("No %d\n", miss);
system("pause");
return 0;
}
```
Binary file removed rebuild_btree.pdf
Binary file not shown.

0 comments on commit 14f3df4

Please sign in to comment.