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