A.4(C++)

写出一个键和值的类型都可以是string或int的哈希表类, HT。
本题难度大,参考答案有200行。

注意

HT不是一个模版类,但是HT的一个对象可以同时使用int和string的对象作为键。
EXAMPLE INPUT

1 2 3 4 5 6 7 8
EXAMPLE OUTPUT

4
2
4
6
8

主程序(不能修改)

#include "source.cpp"

#include <iostream>
#include <sstream>
using namespace std;

int main() {
    HT map;
    
    int key1;
    int value1;
    cin >> key1 >> value1;
    map.put(key1, value1);
    
    string key2;
    string value2;
    cin >> key2 >> value2;
    map.put(key2, value2);
    
    int key3;
    string value3;
    cin >> key3 >> value3;
    map.put(key3, value3);
    
    string key4;
    int value4;
    cin >> key4 >> value4;
    map.put(key4, value4);
    
    cout << map.size() << endl;
    cout << (int)map[key1] << endl;
    cout << (string)map[key2] << endl;
    cout << (string)map[key3] << endl;
    cout << (int)map[key4] << endl;
}

参考答案
俞泽斌不知道哪来的答案

上一篇: C.1(C++) 下一篇: A.3 (C++)
支持 makedown语法