A.小红的字符串切割
思路:
拿到了一个长度为偶数的字符串,请你将其切割成长度相等的两部分并输出
Code:
#include<bits/stdc++.h> using namespace std; int main() { string s; cin >> s; for (int i = 0; i < s.size() / 2; i++) { cout << s[i]; } cout << '\n'; for (int i = s.size() / 2; i < s.size(); i++) { cout << s[i]; } return 0; }
B.小红的数组分配
思路:
拿2 * n的数组 能不能组成每个ai = bi如果可以输出a 和 b 不能则输出-1
Code:
#include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<int, int> mp; for (int i = 1, x; i <= 2 * n; i++) { cin >> x; mp[x]++; } for (auto [i, j] : mp) { if (j & 1) { return cout << -1, 0; } } for (int T = 1; T <= 2; T++) { for (auto [i, j] : mp) { for (int k = 1; k * 2 <= j; k++) { cout << i << ' '; } } cout << '\n'; } return 0; }
标签:main,cout,int,namespace,35,牛客,mp,include,Round From: https://www.cnblogs.com/youhualiuh/p/18050882