8.13 科大讯飞C++笔试
1. 最大优美排列(AC)
#include <iostream> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cout << n - i << " "; } } // 64 位输出请用 printf("%lld")
2. 小红走字符串(过90%,被卡,不知道原因)
#include <iostream> #include <string> using namespace std; int main() { int n; long k; cin >> n >> k; string str; cin >> str; for (int i = 1; i < str.size(); i++) { int consume = str[i] - str[i - 1]; k -= consume; if (k < 0 && i != str.size() - 1) { cout << -1; } } cout << k; } // 64 位输出请用 printf("%lld")
3. 科大讯飞机器存储问题(被卡,过了20%,不知道原因)
#include <iostream> #include <vector> #include <unordered_map> using namespace std; int main() { int n; cin >> n; vector<int> veca(n); unordered_map<int, int> mpa; for (int i = 0; i < n; i++) { cin >> veca[i]; mpa[veca[i]] = i; } vector<int> vecb(n); unordered_map<int, int> mpb; for (int i = 0; i < n; i++) { cin >> vecb[i]; mpb[vecb[i]] = i; } long maxNum = n * (n + 1); for (int i = 0; i < n; i++) { int posa = mpa[veca[i]]; int posb = mpb[veca[i]]; int numSame = 0; while (posa < n && posb < n && veca[posa] == vecb[posb]) { numSame++; posa++; posb++; } maxNum -= numSame; } cout << maxNum; }
如果有知道我是哪里写的不对的,欢迎告诉我,谢谢!