baidu_27549073 2017-08-22 02:20 采纳率: 50%
浏览 890
已结题

ACM编译失败,是不能使用map吗,本地是对的

http://poj.org/problem?id=1002

#include <map>
#include <iostream>
using namespace std;
map<const char, int> phonemap = {
                                    { 'A', 2 },
                                    { 'B', 2 },
                                    { 'C', 2 },
                                    { 'D', 3 },
                                    { 'E', 3 },
                                    { 'F', 3 },
                                    { 'G', 4 },
                                    { 'H', 4 },
                                    { 'I', 4 },
                                    { 'J', 5 },
                                    { 'K', 5 },
                                    { 'L', 5 },
                                    { 'M', 6 },
                                    { 'N', 6 },
                                    { 'O', 6 },
                                    { 'P', 7 },
                                    { 'R', 7 },
                                    { 'S', 7 },
                                    { 'T', 8 },
                                    { 'U', 8 },
                                    { 'V', 8 },
                                    { 'W', 9 },
                                    { 'X', 9 },
                                    { 'Y', 9 } 
                                };
int main()
{
    int num;
    cin >> num;
    //int phone[7 * num];
    map<int, int> phones;
    for (int i = 0; i < num; i++)
    {
        int *phone = new int[7];
        int curPhoneIndex = 0;
        char inputphone[16];
        cin >> inputphone;
        for (int i = 0; i < 16; i++)
        {
            if (inputphone[i] > 47 && inputphone[i] < 59)
            {
                phone[curPhoneIndex] = inputphone[i] - 48;
                curPhoneIndex++;
            }
            else if (phonemap[inputphone[i]] == NULL)
            {

            }
            else
            {
                phone[curPhoneIndex] = phonemap[inputphone[i]];
                curPhoneIndex++;
            }
        }
        int phonenumber = phone[0] * 1000000 + phone[1] * 100000 + phone[2] * 10000 + phone[3] * 1000 + phone[4] * 100 + phone[5] * 10 + phone[6];
        if (phones.find(phonenumber) == phones.end())
        {
            phones.insert(map<int,int>::value_type(phonenumber, 1));
        }
        else
        {
            phones[phonenumber] += 1;
        }
    }
    map<int,int>::iterator it = phones.begin();
    bool has_count_2 = false;
    for (; it != phones.end(); it++)
    {
        if (it->second < 2)
        {
            continue;
        }
        int i = 0;
        cout << it->first / 1000000;
        cout << it->first % 1000000 / 100000;
        cout << it->first % 100000 / 10000;
        cout << "-";
        cout << it->first % 10000 / 1000;
        cout << it->first % 1000 / 100;
        cout << it->first % 100 / 10;
        cout << it->first % 10;
        cout << " " << it->second << endl;
        has_count_2 = true;
    }
    if (!has_count_2)
    {
        cout << "No duplicates."<< endl;
    }
    return 0;
}


  • 写回答

2条回答 默认 最新

  • T_world 2017-08-22 02:53
    关注

    OJ给出的报错信息是什么呢

    评论

报告相同问题?

悬赏问题

  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式