POJ 1002 487-3279

http://poj.org/problem?id=1002
这道题主要是考察字符串的相关操作:替换字符串中的指定字符、删除字符串中的指定字符、字符串排序、字符串比较。

#include 
#include 
#include 

using namespace std;

void delchar(char str[], char c)
{
    int i=0, j=0;
    for(i=0;str[i]!='\0';i++)
    {
        if(str[i]=='A' || str[i]=='B' || str[i]=='C')
            str[i]='2';
        else if(str[i]=='D'||str[i]=='E' || str[i]=='F')
            str[i]='3';
        else if(str[i]=='G'||str[i]=='H' || str[i]=='I')
            str[i]='4';
        else if(str[i]=='J'||str[i]=='K' || str[i]=='L')
            str[i]='5';
        else if(str[i]=='M'||str[i]=='N' || str[i]=='O')
            str[i]='6';
        else if(str[i]=='P'||str[i]=='R' || str[i]=='S')
            str[i]='7';
        else if(str[i]=='T'||str[i]=='U' || str[i]=='V')
            str[i]='8';
        else if(str[i]=='W'||str[i]=='X' || str[i]=='Y')
            str[i]='9';
        if(str[i]!=c)
        {
            str[j]=str[i];
            j++;
        }

    }
    str[j]='\0';
}

int compare(const void *i, const void *j)
{
    return strcmp(*(char **)i, *(char(**))j);
}


void unvs(char a[])
{
    int i;
    for(i=6;i>2;i--)
    {
        a[i+1]=a[i];
    }
    a[3]='-';
    a[8]='\0';
}

int iseql(char a[], char b[])
{
    int i;
    for (i=0;a[i]!='\0'&&b[i]!='\0';i++)
    {
        if(a[i]!=b[i])
            return 0;
    }
    return 1;
}


int main()
{
    int i, n;
    scanf("%d", &n);
    char **a = (char **)malloc(sizeof(char *)*n);
    for(i=0;i1)
        {
            printf("%s %d\n", a[i], cnt[i]);
        }
        else
        {
            num++;
        }
    }
    if(num==n)
        printf("No duplicates. ");

    return 0;
}

你可能感兴趣的:(POJ 1002 487-3279)