博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1039 到底买不买
阅读量:4690 次
发布时间:2019-06-09

本文共 900 字,大约阅读时间需要 3 分钟。

题目链接:

题解:

1 /* 2 *将字符串中的单个字符变为int值,用数组ans的下表保存。 3 */ 4 #include 
5 #include
6 using namespace std; 7 const int MAXN = 200; 8 9 int main() {10 string str1, str2;11 cin >> str1 >> str2;12 int ans[MAXN] = { 0 };13 for (int i = 0; i < str1.size(); i++)14 ans[str1[i] - 48]++;15 int count = 0, cnt = 0;16 for (int i = 0; i < str2.size(); i++) {17 int j = 0;18 for (; j < str1.size(); j++) {19 if (ans[str1[j] - 48] != 0 && str2[i] == str1[j]) {20 ans[str1[j] - 48]--;21 count++;22 break;//容易忘记23 }24 }25 if (j == str1.size()) cnt++;26 }27 if (count == str2.size()) cout << "Yes" << " " << str1.size() - str2.size();28 else cout << "No" << " " << cnt;29 return 0;30 }

 

转载于:https://www.cnblogs.com/Gzu_zb/p/9567413.html

你可能感兴趣的文章