时刻多日没打竟然退步了
A.小红的葫芦
思路:
五个元素 三个相同 另外两个相同 可以通过数组排序写 也可以map等等方法很多
Code:
#include<bits/stdc++.h> using namespace std; map <int, int> mp; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); for (int i = 1; i <= 5; i++) { int x; cin >> x; mp[x] ++; } int ok = 0; if (mp.size() == 2) { for (auto [x, y] : mp) { if (y == 2) ok += 1; if (y == 3) ok += 1; } cout << (ok == 2 ? "YES\n" : "NO\n"); } else { cout << "NO\n"; } return 0; }
B.茉茉的密码
思路:
找到他们的公共连续串且保证答案肯定有,其实贪心的想一下 只要一个字母在各个子串中存在就可以,于是枚举一下即可
Code:
#include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector <int> v(26, 0); for (int i = 1; i <= n; i++) { string s; cin >> s; vector <bool> vis(26, 0); for (char ch : s) { if (!vis[ch - 'a']) { vis[ch - 'a'] = 1; v[ch - 'a'] ++; } } } for (int i = 0; i < 26; i++) { if (v[i] >= n) { cout << char(i + 'a') << '\n'; return 0; } } return 0; }
标签:ch,cout,vis,int,47,牛客,mp,tie,Round From: https://www.cnblogs.com/youhualiuh/p/18251248