HDU 2651 Spring Festival couplets

Source: Internet
Author: User

Spring Festival CoupletsTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 194 Accepted Submission (s): 82


Problem Descriptionwhen The Spring Festival is coming and people always paste Spring festival couplets onto the wall. Now Dandelion ' s father have bought several spring festival couplets, he wants to know how many pairs of Spring festival Cou PLETs can been consisted with these spring festival couplets. As we know, Spring Festival couplets is carefully balanced. Such as AABBCCDD can only is matched with AABBCCDD or Bbddeeff or Aabbaabb ...

Inputa 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 would not be exceed 8.
Outputfor every case, print the number of pairs can is made by these spring festival couplets.
Sample Input
6ABCCCDALLLMNNODEZZZBFAAABCCDKKKXPPQAAA

Sample Output
4

Test instructions more clear on the couplet, can match the pairing asked how many pairs, directly with map map to do, each time look before and the current string the same pattern appeared a few times, add on it, the input is finished statistics, will not repeat. However, the afternoon of the game, the mood does not know why it is so irritable, water problems are not written, or bubble feet home wash and sleep.
#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;}











Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 2651 Spring Festival couplets

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.