acm_hdu Problem Archive 1004
2015-05-17 16:38
246 查看
#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;
}
#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;
}
相关文章推荐
- 【ACM】hdu_zs2_1004_Problem D _201308030856
- http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1004&ojid=1&cid=6866&hide=1&problem=Pro
- acm_hdu Problem Archive 1002
- hdu 4731 Minimum palindrome 找规律 (2013 ACM/ICPC Asia Regional Chengdu Online 1004)
- 2014多校第十场1004 || HDU 4974 A simple water problem
- HDU 5475 An easy problem(用大数模板,你就上当了)——2015 ACM/ICPC Asia Regional Shanghai Online
- http://acm.hdu.edu.cn/showproblem.php?pid=1385
- http://acm.hdu.edu.cn/showproblem.php?pid=3791&&二叉搜索树
- http://acm.hdu.edu.cn/showproblem.php?pid=2159
- http://acm.hdu.edu.cn/showproblem.php?pid=1238
- http://acm.hdu.edu.cn/showproblem.php?pid=4148
- http://acm.hdu.edu.cn/showproblem.php?pid=2795 更新节点构造线段数很关键,询问特殊
- A very hard mathematic problem (HDU 4282) acm
- http://acm.hdu.edu.cn/showproblem.php?pid=1541 结点更新求最左区间的个数
- http://acm.hdu.edu.cn/showproblem.php?pid=3450 线段树 + dp
- 欧拉回路的应用&&http://acm.hdu.edu.cn/showproblem.php?pid=3018
- http://acm.hdu.edu.cn/showproblem.php?pid=3336
- http://acm.hdu.edu.cn/showproblem.php?pid=1394&&线段树之求逆序数
- http://acm.hdu.edu.cn/showproblem.php?pid=4337&&dfs
- http://acm.hdu.edu.cn/showproblem.php?pid=1166