pku 1002

submit了十几次了,终于AC了,用c++ stl map+string做的 

 1  #include  < iostream >
 2  #include  < map >
 3  #include  < string >
 4  using   namespace  std;
 5 
 6  string  format( char   * s)
 7  {
 8       int  i,index;
 9       char  r[ 20 ];
10      index  =   0 ;
11      i = 0 ;
12       while  (s[i] != ' \0 ' )
13      {
14           if (s[i] >= ' A ' && s[i] <= ' R ' )
15              r[index ++ =  (s[i]  -   ' A ' ) / 3   +   ' 2 ' ;
16           else   if (s[i] >= ' S ' && s[i] <= ' Y ' )
17          {
18              r[index ++ =  (s[i]  -   ' A '   -   1 ) / 3   +   ' 2 ' ;
19          }
20           else   if (s[i] != ' - ' )
21              r[index ++ =  s[i];
22           if (index == 3 )
23              r[index ++ =   ' - ' ;
24          i ++ ;
25      }
26      r[index]  =   ' \0 ' ;
27       string  str(r);
28       return  str;
29  }
30 
31  int  main()
32  {
33       int  i,n;
34       char  s[ 20 ];
35       string  str;
36      map  < string , int >  m;
37      map  < string , int > ::const_iterator m_it;
38       int  flag  =   0 ;
39      cin >> n;
40       for  (i = 0 ; i < n; i ++ )
41      {
42          cin >> s;
43          str = format(s);
44           if  (m.find(str) != m.end())
45          {
46              m[str] ++ ;
47          }
48           else
49              m[str] = 1 ;
50      }
51      m_it  =  m.begin();
52 
53       while  (m_it !=  m.end())
54      {
55           if (m_it -> second > 1 )
56          {
57              flag  =   1 ;
58              cout << m_it -> first << "   " << m_it -> second << endl;
59          }
60          m_it ++ ;
61      }
62       if ( ! flag)
63          cout << " No duplicates. " << endl;
64       return   0 ;

65 } 

ContractedBlock.gifCode

转载于:https://www.cnblogs.com/cnicefire/archive/2009/04/14/pku_1002.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值