hdu 2651 Spring festival couplets

2582 ワード

Spring festival couplets
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 194    Accepted Submission(s): 82
Problem Description
When the spring festival is coming , people always paste spring festival couplets onto the wall.Now dandelion's father has bought several spring festival couplets, he wants to know how many pairs of spring festival couplets can been consisted with these spring festival couplets.As we know ,spring festival couplets are carefully balanced.Such as AABBCCDD can only be matched with AABBCCDD or BBDDEEFF or AABBAABB ...
 
Input
A number n stands for the number of the spring festival couplets.(2≤n≤110000)
Then n lines ,each line contains a string made by capital letters. Such as AABBCCDD,AABBCCD.The length of the string will not exceed 8.
 
Output
For every case ,print the number of pairs can be made by these spring festival couplets.
 
Sample Input

   
   
   
   
6 ABCCCDA LLLMNNO DEZZZBF AAABCCD KKKXPPQ AAA

 
Sample Output

   
   
   
   
4

 
題意は比較的に明確に対聯して、対聯することができるのは対になってどれだけ対を配合することができるかを聞いて、直接mapマッピングでして、毎回前と現在の列の同じモードの出現を見て何回、加算すればいいので、入力が終わったら統計が終わって、繰り返しません.
しかし午后の试合の时、気持ちはどうしてそんなにイライラすることができて、水题はすべてうまく书けなくて、やはり足を浸して家に帰って洗濯して寝ましょう.
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#
using namespace std;

char s[10];

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        map<int,int>ss;
        int ans=0;
        for(int i=0;i<n;i++)
        {
            scanf("%s",s);
            int len=strlen(s);
            int p=0;
            int cnt=1;
            for(int j=0;j<len;j++)
            {
                if(j==0) p=1;
                if(s[j-1]==s[j]) p=p*10+cnt;
                else p=p*10+(++cnt);
            }
            if(len<8)
            {
                for(int j=len;j<8;j++)
                {
                     p=p*10+9;
                }
            }

            ans+=ss[p];
            ss[p]++;
        }

        printf("%d
",ans); } return 0; }