2013
11-26

# Let the Balloon Rise

Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges’ favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.This year, they decide to leave this lovely job to you.

Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) — the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.A test case with N = 0 terminates the input and this test case is not to be processed.

For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.

5
green
red
blue
red
red
3
pink
orange
pink
0

red
pink

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;

int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
int a,b;
scanf("%d %d",&a,&b);

int Palind[110000],pnum=0;
int n,m,k,p,q;

//求所有的回文数

for(n=1; n<=9; n++)
Palind[pnum++]=n;
for(n=1; n<=9; n++)
Palind[pnum++]=11*n;
for(n=1; n<=9; n++)
for(m=0; m<=9; m++)
Palind[pnum++]=101*n+10*m;
for(n=1; n<=9; n++)
for(m=0; m<=9; m++)
Palind[pnum++]=1001*n+110*m;
for(n=1; n<=9; n++)
for(m=0; m<=9; m++)
for(k=0; k<=9; k++)
Palind[pnum++]=10001*n+1010*m+100*k;
for(n=1; n<=9; n++)
for(m=0; m<=9; m++)
for(k=0; k<=9; k++)
Palind[pnum++]=100001*n+10010*m+1100*k;
for(n=1; n<=9; n++)
for(m=0; m<=9; m++)
for(k=0; k<=9; k++)
for(p=0; p<=9; p++)
Palind[pnum++]=1000001*n+100010*m+10100*k+1000*p;
for(n=1; n<=9; n++)
for(m=0; m<=9; m++)
for(k=0; k<=9; k++)
for(p=0; p<=9; p++)
Palind[pnum++]=10000001*n+1000010*m+100100*k+11000*p;
for(n=1; n<=9; n++)
for(m=0; m<=9; m++)
for(k=0; k<=9; k++)
for(p=0; p<=9; p++)
for(q=0; q<=9; q++)
Palind[pnum++]=100000001*n+10000010*m+1000100*k+101000*p+10000*q;
//判断素数
for(int i=0;i<pnum;i++)
{
if(Palind[i]>b)
{
break;
}
int q = sqrt(Palind[i]) + 1;
int flag = 0;
for(int j = 2;j<q;j++)
{
if(Palind[i]%j == 0)
{
flag = 1;
break;
}
}
if(flag == 0 && Palind[i]>=a)
{
printf("%d\n",Palind[i]);
}
}

return 0;
}

1. 第二块代码if(it != mp.end())应改为if(it != mp.end() && (i+1)!=(it->second +1))；因为第二种解法如果数组有重复元素 就不正确

2. 代码是给出了，但是解析的也太不清晰了吧！如 13 abejkcfghid jkebfghicda
第一步拆分为 三部分 (bejk, cfghi, d) * C(13,3)，为什么要这样拆分，原则是什么？

3. #include <cstdio>

int main() {