Chinaunix首页 | 论坛 | 博客
  • 博客访问: 69657
  • 博文数量: 13
  • 博客积分: 247
  • 博客等级: 二等列兵
  • 技术积分: 138
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-02 18:17
文章分类

全部博文(13)

文章存档

2015年(1)

2014年(1)

2013年(1)

2012年(2)

2011年(8)

我的朋友

分类: C/C++

2013-05-07 23:31:41


点击(此处)折叠或打开

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>

  4. #define MAX_NUMBER 10000000
  5. #define encode_number_of(a) (Encoded_numbers[(a)/3])
  6. #define pos(a) ((a)%MAX_NUMBER)

  7. char Source_characters[24] = {'A','B','C','D','E','F','G','H','I','J','K','L',
  8.        'M','N','O','P','R','S','T','U','V','W','X','Y'};
  9. char Encoded_numbers[8] = {'2','3','4','5','6','7','8','9'};
  10. long Count_of_telephone[MAX_NUMBER] = {0};

  11. long index_of_character(char C_array[],long length,char a)
  12. {
  13.    long index = -1 ;
  14.    long i;
  15.    for(i = 0 ;i< length; i++ )
  16.   {
  17.      if(C_array[i] == a)
  18.     {
  19.       index=i;
  20.       break;
  21.     }
  22.   }
  23.    return index;
  24. }

  25. void Transform_to_standard_number(char* Source_number,char* Result_number)
  26. {
  27.     char* src_ptr = Source_number;
  28.     int Count = 0;
  29.     while(*src_ptr)
  30.     {
  31.       if(*src_ptr == '-' || *src_ptr=='Q' || *src_ptr == 'Z')
  32.       {
  33.          src_ptr++;
  34.          continue;
  35.       }
  36.       long index = index_of_character(Source_characters,24,*src_ptr);
  37.       if(index == -1)
  38.       {
  39.          Result_number[Count] = *src_ptr;
  40.       }
  41.       else
  42.       {
  43.          Result_number[Count] = encode_number_of(index);
  44.       }
  45.       if(++Count == 3)
  46.       {
  47.          Result_number[Count] = '-';
  48.          ++Count;
  49.       }
  50.       src_ptr++;
  51.     }
  52.     Result_number[Count]='\0';
  53. }

  54. void Report_number_count(char* reported_telephone)
  55. {
  56.      char Pure_telephone[8] = "";
  57.      strncpy(Pure_telephone,reported_telephone,3);
  58.      strncpy(Pure_telephone+3,reported_telephone+4,4);
  59.      long Number_of_telephone = atol(Pure_telephone);
  60.      Count_of_telephone[pos(Number_of_telephone)]++;
  61. }


  62. int main()
  63. {
  64.    long Case_total,Counter;
  65.    int existFlag = 0;
  66.    char Case_input[300] = "";
  67.    char standard_format[9] = "";
  68.    char number_string[8]="";
  69.    scanf("%ld",&Case_total);
  70.    for(Counter=1;Counter<=Case_total;Counter++)
  71.    {
  72.        scanf("%s",Case_input);
  73.        Transform_to_standard_number(Case_input,standard_format);
  74.        Report_number_count(standard_format);
  75.        strncpy(Case_input,"",sizeof(Case_input));
  76.        strncpy(standard_format,"",sizeof(standard_format));
  77.    }
  78.    for(Counter=0;Counter<MAX_NUMBER;Counter++)
  79.    {
  80.        if( Count_of_telephone[Counter] > 1)
  81.        {
  82.           sprintf(number_string,"%07ld",Counter);
  83.           Transform_to_standard_number(number_string,standard_format);
  84.           printf("%s %ld\n",standard_format,Count_of_telephone[Counter]);
  85.           if(existFlag == 0)
  86.           {
  87.              existFlag = 1;
  88.           }
  89.        }
  90.    }
  91.    if(existFlag == 0)
  92.    {
  93.        printf("No duplicates.\n");
  94.    }
  95.    return 0;
  96. }

阅读(1696) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~