Untitled
unknown
plain_text
a year ago
1.5 kB
4
Indexable
#include<stdio.h> #include<unordered_map> #include<string> #include<iostream> using namespace std; class List { public: int originList[10000]; unordered_map<int, int> changeMap = unordered_map<int,int>(); bool isCopy; }; unordered_map<string, List> hm = unordered_map<string, List>(); void init() { hm.clear(); } void makeList(char mName[], int mLength, int mListValue[]) { List list; int i = 0; while (i < mLength) { list.originList[i] = mListValue[i]; i++; } hm[mName] = list; } void copyList(char mDest[], char mSrc[], bool mCopy) { List srcList = hm[mSrc]; if (!mCopy) hm[mDest] = srcList; else { List list; int i = 0; if (srcList.originList[i]) { list.originList[i] = srcList.originList[i]; i++; } list.changeMap = srcList.changeMap; list.isCopy = true; srcList.isCopy = true; hm[mDest] = list; } } void updateElement(char mName[], int mIndex, int mValue) { List list = hm[mName]; if (list.isCopy) list.changeMap[mIndex] = mValue; else list.originList[mIndex] = mValue; } int element(char mName[], int mIndex) { List list = hm[mName]; if (list.changeMap[mIndex]) { cout << "ok " << endl; return list.changeMap[mIndex]; } return list.originList[mIndex]; }
Editor is loading...
Leave a Comment