hdu 2651 Spring festival couplets

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\n",ans);
    }

    return 0;
}











评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值