请问为什么第一个代码能过第二个就过不了,两个都能过样例
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, num, score;
string name;
map<string, int> mp;
map<string, int>::iterator it;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> num;
switch (num) {
case 1:
cin >> name >> score;
mp[name] = score;
cout << "OK" << endl;
break;
case 2:
cin >> name;
it = mp.find(name);
if (it != mp.end()) {
cout << mp[name] << endl;
} else {
cout << "Not found" << endl;
}
break;
case 3:
cin >> name;
it = mp.find(name);
if (it != mp.end()) {
mp.erase(it);
cout << "Deleted successfully" << endl;
} else {
cout << "Not found" << endl;
}
break;
case 4:
cout << mp.size() << endl;
break;
}
}
// cout.flush();
// system("pause");
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, num, score;
string name;
map<string, int> mp;
map<string, int>::iterator it;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> num;
switch (num) {
case 1:
cin >> name >> score;
mp.insert(make_pair(name, score));
cout << "OK" << endl;
break;
case 2:
cin >> name;
it = mp.find(name);
if (it != mp.end()) {
cout << it->second << endl;
} else {
cout << "Not found" << endl;
}
break;
case 3:
cin >> name;
it = mp.find(name);
if (it != mp.end()) {
mp.erase(it);
cout << "Deleted successfully" << endl;
} else {
cout << "Not found" << endl;
}
break;
case 4:
cout << mp.size() << endl;
break;
}
}
// cout.flush();
// system("pause");
return 0;
}