zoukankan      html  css  js  c++  java
  • POJ1002_487-3279_C++

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

      我知道你们最需要的是这个 [ 手动滑稽 ]

      

      STD 给出的方法是丢进一个数组,然后排序,相邻的是重复的

      这个方法,时间复杂度很不错,也确实很好,但是最快的写法是

      直接丢进对应的数组统计,然后 for 一遍数组看是否大于 1

      注意没有满 7 位的时候要输出前导零

     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<cstring>
     4 using namespace std;
     5 
     6 char a[255],s[200],w[10];
     7 int b[10000000];
     8 int main()
     9 {
    10     int i,j,n,len,x;
    11     bool flag=1;
    12     scanf("%d
    ",&n);
    13     a['A']=a['B']=a['C']='2';
    14     a['D']=a['E']=a['F']='3';
    15     a['G']=a['H']=a['I']='4';
    16     a['J']=a['K']=a['L']='5';
    17     a['M']=a['N']=a['O']='6';
    18     a['P']=a['R']=a['S']='7';
    19     a['T']=a['U']=a['V']='8';
    20     a['W']=a['X']=a['Y']='9';
    21     for (i=1;i<=n;i++)
    22     {
    23         scanf("%s",s);
    24         len=strlen(s);
    25         x=0;
    26         for (j=0;j<len;j++)
    27         {
    28             if (s[j]>='A'&&s[j]<='Z') s[j]=a[s[j]];
    29             if (s[j]>='0'&&s[j]<='9') x=x*10+s[j]-'0';
    30         }
    31         b[x]++;
    32     }
    33     for (i=0;i<10000000;i++)
    34         if (b[i]>1)
    35         {
    36             for (x=i,j=1;j<=7;j++)
    37             {
    38                 w[j]=x%10+'0';
    39                 x/=10;
    40             }
    41             for (;j;j--) putchar(j>5?w[j-1]:j<5?w[j]:'-');
    42             printf(" %d
    ",b[i]);
    43             flag=0;
    44         }
    45     if (flag) printf("No duplicates.
    ");
    46     return 0;
    47 }

      见到的好博客,可以看出真的是用心写了

      http://blog.csdn.net/thebestdavid/article/details/10986813

    版权所有,转载请联系作者,违者必究

    联系方式:http://www.cnblogs.com/hadilo/p/5932395.html

  • 相关阅读:
    git
    ComfortColor.xcs
    使用Jackson时转换JSON时,日期格式设置
    json和jsonp
    powerdesigner 将表中name列值复制到comment列 (保留原有comment)
    下滑线驼峰互转
    Tomcat
    git stash
    gitignore
    例题:大图轮播
  • 原文地址:https://www.cnblogs.com/hadilo/p/5974535.html
Copyright © 2011-2022 走看看