poj1002

简单模拟

View Code
#include <iostream>

#include <string>

#include <algorithm>

using namespace std;



const    int        maxn = 100002;



int        n;

string    telephone[maxn];



void make(string &a)

{

    int        i;



    for (i = 0; i < a.length(); i++)

    {

        while (a[i] == '-' && i < a.length())

            a.erase(i, 1);

        if (i >= a.length())

            break;

        if (a[i] <= 'Z' && a[i] >= 'A')

        {

            if (a[i] == 'S')

            {

                a[i] = '7';

                continue;

            }

            if (a[i] == 'V')

            {

                a[i] = '8';

                continue;

            }

            if (a[i] == 'Y')

            {

                a[i] = '9';

                continue;

            }

            a[i] = (a[i] - 'A') / 3 + 2 + '0';

        }

    }

    a.insert(3, "-");

}



int main()

{

    int        i, j;

    bool    did = false;



    //freopen("t.txt", "r", stdin);

    cin >> n;

    for (i = 0; i < n; i++)

    {

        cin >> telephone[i];

        make(telephone[i]);

    }

    sort(telephone, telephone + n);

    j = 1;

    for (i = 1; i < n; i++)

    {

        if (telephone[i] != telephone[i - 1])

        {

            if (j > 1)

            {

                cout << telephone[i - 1] << " " << j << endl;        

                did = true;

            }

            j = 1;

        }

        else

            j++;

    }

    if (j > 1)

    {

        cout << telephone[n - 1] << " " << j << endl;

        did = true;

    }

    if (!did)

        cout << "No duplicates." << endl;

    return 0;

}

你可能感兴趣的:(poj)