两个数之和等于target值

void checkTarget()
{
    int target = 14;
    int buf[] = { 8, 2, 9, 10, 5, 4, 6 };
    std::map<int, int> tmpMap;
    for (int i = 0; i < sizeof(buf); i ++)
    {
        std::map<int, int>::iterator itor = tmpMap.find(target - buf[i]);
        if (itor == tmpMap.end())
        {
            tmpMap.insert(pair<int, int>(buf[i], i));
        }
        else
        {
            int index1 = itor->second;
            int index2 = i;
            cout << index1 << ":" << index2 << endl;
            break;
        }
    }
}
青青园中葵,朝露待日晞。 阳春布德泽,万物生光辉。 常恐秋节至,焜黄华叶衰。 百川东到海,何时复西归? 少壮不努力,老大徒伤悲!
原文地址:https://www.cnblogs.com/weiyouqing/p/14620165.html