社区讨论

全wa警告,分数类型是int, 我整了个double 一直wa(恼)

P5266【深基17.例6】学籍管理参与者 3已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@lo29afmu
此快照首次捕获于
2023/10/23 10:05
2 年前
此快照最后确认于
2023/11/03 10:17
2 年前
查看原帖
一起加油hh... 下面贴个 map 的 ac 代码
CPP
#include<iostream>
#include<map>
#include<algorithm>

using namespace std;
map<string,int> mp;

int main()
{
    int n;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        int op;
        cin >> op;
        string name;
        if(op != 4) cin >> name;  // 4 不要需要名字
        if(op == 1)
        {
            double sc;
            cin >> sc;
            mp[name] = sc;    // 包括更新与添加
            cout << "OK" << endl;
        }else if(op == 2)
        {
            if(mp.count(name)) cout << mp[name] << endl;
            else cout << "Not found" << endl;
        }else if(op == 3)
        {
            if(mp.count(name))
            {
                mp.erase(name);
                cout << "Deleted successfully" << endl;
            }
            else cout << "Not found" << endl;
        }else cout << mp.size() << endl;
    }

    return 0;
}

回复

2 条回复,欢迎继续交流。

正在加载回复...