POJ 1002 487-3279

1. 试了各种数据类型保存输入的字符串,比如string,字符数组。在string类型中,不能一个一个字符地拷贝字符串,因为字符串末尾还有一个字符。

2. 字符型数字转换成int类型;

3. 自我感觉change函数写的比较巧妙,跟Curling 2.0有点类似。是把一个数组(有重复元素)无重复的放到另外一个数组。



#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
using namespace std;
int telnum[100010];
int tel[100010][7];
int n;
struct Node
{
    int ans;
    int num;
} node[100010];
bool cmp(int a, int b)
{
    return a < b;
}
void change(int k, string str)
{
    int i, j = 0;
    for(i = 0; i < 7; i++)
    {

        while(str[j] == '-')
            j++;
        if(str[j] == '0' || str[j] == '1' || str[j] == '2' || str[j] == '3' || str[j] == '4' || str[j] == '5' || str[j] == '6' || str[j] == '7' || str[j] == '8' || str[j] == '9')
        {
            tel[k][i] = str[j] - '0';//操,=写成==了,测试了一个多小时。。。
            j++;
            continue;
        }
        if(str[j] == 'A' || str[j] == 'B' || str[j] == 'C')
        {
            tel[k][i] = 2;
            j++;
            continue;
        }

        if(str[j] == 'D' || str[j] == 'E' || str[j] == 'F')
        {
            tel[k][i] = 3;
            j++;
            continue;
        }
        if(str[j] == 'G' || str[j] == 'H' || str[j] == 'I')
        {
            tel[k][i] = 4;
            j++;
            continue;
        }
        if(str[j] == 'J' || str[j] == 'K' || str[j] == 'L')
        {
            tel[k][i] = 5;
            j++;
            continue;
        }
        if(str[j] == 'M' || str[j] == 'N' || str[j] == 'O')
        {
            tel[k][i] = 6;
            j++;
            continue;
        }
        if(str[j] == 'P' || str[j] == 'R' || str[j] == 'S')
        {
            tel[k][i] = 7;
            j++;
            continue;
        }
        if(str[j] == 'T' || str[j] == 'U' || str[j] == 'V')
        {
            tel[k][i] = 8;
            j++;
            continue;
        }
        if(str[j] == 'W' || str[j] == 'X' || str[j] == 'Y')
        {
            tel[k][i] = 9;
            j++;
            continue;
        }
    }
}
int getnum()
{
    int i, j = 0;
    for(i = 0; j < n; i++)
    {
        node[i].num = 0;
        node[i].ans = telnum[j];
        node[i].num++;
        while(telnum[j] == telnum[j+1])
        {
            j++;
            node[i].num++;
        }
        j++;
    }
    return i;
}

int main()
{
    string str;
    int count = 0;
    cin >> n;
    memset(tel, 0, sizeof(tel));
    for(int i = 0; i < n; i++)
    {
        cin >> str;
        change(i, str);
/*        for(int j = 0; j < 7; j++)
        {
            cout << tel[i][j];
        }
        cout << endl;*/
        telnum[i] = tel[i][0] * 1000000 + tel[i][1] * 100000 + tel[i][2] * 10000 + tel[i][3] * 1000 + tel[i][4] * 100 + tel[i][5] * 10 + tel[i][6];
    }
    sort(telnum, telnum + n, cmp);
    int m = getnum();
    for(int i = 0; i < m; i++)
    {
        if(node[i].num > 1)
        {
            cout << node[i].ans / 10000 << '-' << node[i].ans % 10000 << ' ' << node[i].num << endl;
        }
        else count++;
    }
    if(count == n)
        cout << "No duplicates." << endl;
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值