acm_hdu Problem Archive 1004

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
int n = 0;
while (scanf("%d",&n) != EOF && n!= 0)
{
char str[1000][16];//只对各不相同的颜色进行存储
memset(str,0,sizeof(str));//all set to be NUL
char tmp[16];
int count[1000] = {0};//对应每个str[i]统计个数
int len = 0;//str长度

for (int i=0; i<n; i++)
{
scanf("%s",tmp);
int tmplen = strlen(tmp);
if (len == 0)//first color
{
strncpy(str[0],tmp,tmplen);
len = 1;
count[0] = 1;
continue;
}

for (int i=0; i<len; i++)
{
if (strcmp(str[i],tmp) == 0)//str[i]和tmp同色,则对应count[i]++
{
count[i]++;
break;
}

if (i == len-1)//之前所有的str[i]和tmp都不同色,添加新色str[len]
{
strncpy(str[len],tmp,tmplen);
count[len] = 1;
len++;
break;//注意此处要break,否则最后一次匹配len++,会导致for额外循环一次!
}
}
}

int max = count[0];
int pos = 0;
for (int i=0; i<len; i++)
{
//printf("%s:%d\n", str[i],count[i]);
if (count[i] > max)
{
max = count[i];
pos = i;
}
}
printf("%s\n",str[pos]);
}
return 0;
}

时间: 2024-08-03 00:18:36

acm_hdu Problem Archive 1004的相关文章

acm_hdu Problem Archive 1002

#include <stdio.h>#include <stdlib.h>#include <string.h> void add(char *a, char *b,char *sum)//字符串a要比字符串b长,或相等{ int len_a = strlen(a); int len_b = strlen(b); char tmp[len_a]; int offset = len_a-len_b; strncpy(tmp+offset,b,len_b);//后面len_

ZOJ Problem Set - 1004 Anagrams by Stack (回溯法)

ZOJ Problem Set - 1004 Anagrams by Stack Time Limit: 2 Seconds      Memory Limit: 65536 KB How can anagrams result from sequences of stack operations? There are two sequences of stack operators which can convert TROT to TORT: [ i i i i o o o o i o i

Problem Archive #1 题解2

接着上一次的题解接着写 E题,水题,The second line contains integers a1,a2,…,ana1,a2,…,an (1≤ai≤10001≤ai≤1000) — all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with xx steps, she w

最左/右边的数-hd1060/1061

左边: http://acm.hdu.edu.cn/showproblem.php?pid=1060 1 #include <iostream> 2 #include <math.h> 3 using namespace std; 4 5 int main() 6 { 7 int n,m,d,i; 8 double l; 9 while(cin>>n) 10 11 { 12 for(i=1;i<=n;i++) 13 { 14 cin>>m; 15 l=

[C#] 逆袭——自制日刷千题的AC自动机攻克HDU OJ

前言 做过杭电.浙大或是北大等ACM题库的人一定对“刷题”不陌生,以杭电OJ为例:首先打开首页(http://acm.hdu.edu.cn/),然后登陆,接着找到“Online Exercise”下的“Problem Archive”,然后从众多题目中选择一个进行读题.构思.编程.然后提交.最后查看题解状态,如果AC了表示这一题被攻克了,否则就要重做了~一般情况下,“刷题”要求精神高度集中且经验丰富,否则很难成功AC,有时候甚至做一题要浪费半天的时间!(有时网速卡了,比抢火车票还要急!) 楼主在

Color the ball 线段树 区间更新但点查询

#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<sstream> #include<algorithm> #include<queue> #include<deque> #include<iomanip> #include<vector> #include<cmath>

_____________________________________动态规划之最长子序列问题______1:两个序列中的______________________________________

动态规划之最长自序列问题....两个字符串中的最长子序列问题. 参考例题杭电1159.....参考文件.lcy老师的课件....在此对lcy老师致敬.. 最长子序列问题....... 下面附上题目 Online Judge Online Exercise Online Teaching Online Contests Exercise Author F.A.Q Hand In Hand Online Acmers Forum | Discuss Statistical Charts Proble

OJ测试数据追溯方法

https://blog.csdn.net/iwts_24/article/details/79240987 我是从这个博客知道还有从比赛官方网站扒测试数据的方法,但是下面的链接有些是失效的. 所以我记录一下自己的步骤:( HDU2732) 1.发现最下方有比赛的名称:Mid-Central USA 2005 2.搜索Mid-Central USA,找到一个官网——虽然写的是2018:ICPC Mid-Central USA Regional Contest 2018 documentation

2014多校第十场1004 || HDU 4974 A simple water problem

题目链接 题意 : n支队伍,每场两个队伍表演,有可能两个队伍都得一分,也可能其中一个队伍一分,也可能都是0分,每个队伍将参加的场次得到的分数加起来,给你每个队伍最终得分,让你计算至少表演了几场. 思路 : ans = max(maxx,(sum+1)/2) :其实想想就可以,如果所有得分中最大值没有和的一半大,那就是队伍中一半一半对打,否则的话最大的那个就都包了. 1 #include <cstdio> 2 #include <cstring> 3 #include <st