MergeRecord_C++中map的使用

//============================================================================
// Name : TTTest.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================ #include <iostream>
#include <stdlib.h>
#include <map>
typedef struct TIME_STRU {
int nIndex; /* 表索引 */
int nValue; /* 值 */
} TABLE_RECORD; void MergeRecord(TABLE_RECORD* pOriRecord, int nOriRecordNum,
TABLE_RECORD* pMergeRst, int* pnMergeRecordNum); using std::cout;
using std::endl;
using std::map;
using std::make_pair; void MergeRecord(TABLE_RECORD* pOriRecord, int nOriRecordNum,
TABLE_RECORD* pMergeRst, int* pnMergeRecordNum) {
map<int, int> inMap; for (int i = ; i < nOriRecordNum; ++i) {
auto ret = inMap.insert(make_pair(pOriRecord[i].nIndex, pOriRecord[i].nValue));
if(!ret.second) {
       // 或者直接+=即可
inMap[pOriRecord[i].nIndex] += pOriRecord[i].nValue);
}
}
cout << inMap.size() << endl;
cout << inMap[] << endl; return;
} int main() {
// TABLE_RECORD pOriRecord[] = { { 1, 3 }, { 2, 3 }, { 2, 8 } };
// cout << pOriRecord[0].nIndex << endl;
//
// int nOriRecordNum = sizeof(pOriRecord) / sizeof(pOriRecord[0]);
// cout << nOriRecordNum << endl;
//
// TABLE_RECORD* pMergeRst;
// int nMergeRecordNum = 0;
// int* pnMergeRecordNum = &nMergeRecordNum;
// MergeRecord(pOriRecord, nOriRecordNum, pMergeRst, pnMergeRecordNum);
int ttt = -;
char s[] = { };
itoa(ttt, s, ); cout << s <<endl;
return ;
}
上一篇:Spark的性能调优杂谈


下一篇:jquery 甘特图开发指南