| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1059 人关注过本帖
标题:请大牛看看我哪错了
只看楼主 加入收藏
编程探索者
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2010-7-21
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:13 
请大牛看看我哪错了
#include <stdio.h>
#include <string.h>
int main()
{
    char str[1001][1001]={0},str1[1001]={0},str2[1001]={0},empty[1001]={0};
    int i,j,N,k,n,h=0,p,flag;
        while(scanf("%d",&N)!=EOF&&N!=0)
        {
            k=0;
            h=0;
         for(i=0;i<N;i++)
        scanf("%s",str[i]);
        for(i=0;i<N;i++)
        {
        n=0;
            p=i;
            for(j=0;j<N;j++)
            {
                strcpy(str1,str[0]);
                if(strcmp(str[p],str[j])==0)
                {
                       n++;
                       strcpy(str1,str[j]);
                }
                k=n;
            

            }
            if(k>h)   
               strcpy(str2,str1);
            h=n;
        }
    printf("%s\n",str2);
       for(i=0;i<N;i++)
           for(j=0;j<1001;j++)
         for(i=0;i<1001;i++)
         {
            str1[i]=0;str2[i]=0;
         }
       }
    return 0;
}
搜索更多相关主题的帖子: str include 
2010-07-21 11:08
sunyh1999
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:14
帖 子:1178
专家分:3032
注 册:2009-5-17
收藏
得分:0 
请问题目要求是什么,要达到什么目的,LZ要写清楚啊

欢迎来到我的博客:http://blog..cn/noisunyuhong
2010-07-21 11:12
LSYHEFENG
Rank: 2
等 级:论坛游民
帖 子:112
专家分:71
注 册:2010-7-17
收藏
得分:2 
这个是杭电1004吧,我也纠结了很久
  
Online Judge Online Exercise Online Game Online Contests Exercise Author
F.A.Q
Hand In Hand
Online Acmers
Forum | Discuss
Statistical Charts
 Problem Archive
Realtime Judge Status
Authors Ranklist
   AC Formular
Code Challenge
 STD Contests
VIP Contests      
Virtual Contests      
C/C++ Exams      
DIY Contests          LSYHEFENG
 Mail 0(0)
 Control Panel
 Sign Out
 

7月16日管理员再次修正“虚拟比赛”的若干Bug,感谢热心用户的支持,期待大家继续测试~ 这里提建议
 
Let the Balloon Rise
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 23450    Accepted Submission(s): 7100


Problem Description
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
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.

 

Output
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.

 

Sample Input
5
green
red
blue
red
red
3
pink
orange
pink
0
 

Sample Output
red
pink
 
2010-07-21 11:15
LSYHEFENG
Rank: 2
等 级:论坛游民
帖 子:112
专家分:71
注 册:2010-7-17
收藏
得分:0 
没看出来,我OUT了,真正的高手也表现在查错上面
2010-07-21 11:20
编程探索者
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2010-7-21
收藏
得分:0 
大家一起探讨探讨,谢谢楼上的关注
2010-07-21 11:23
iFreeBSD
Rank: 4
等 级:业余侠客
威 望:4
帖 子:474
专家分:236
注 册:2007-11-5
收藏
得分:0 
你程序的目的应该是判断并把重复的字符串输出吧。如果是的话,我建议你不要先先编码,先画个图出来看看
你程序的无用变量和循环结构太多。

without further ado, let’s get started
2010-07-21 11:47
flyingcat
Rank: 4
来 自:HDU
等 级:业余侠客
威 望:2
帖 子:55
专家分:230
注 册:2010-7-18
收藏
得分:3 
我当时的AC代码:先看看,吃饭回来再看看楼主的代码……
程序代码:
#include <stdio.h>
#include <string.h>

typedef struct ballon
{
    char ch[16];
    int num;
};

int main()
{
    int n,point,i,max,t_p,flag;
    ballon ball[1001];
    char ch[16];
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0)
            break;
        point=1;
        getchar();
        for(i=0;i<n;i++)
        {
            ball[i].ch[0]='\0';
            ball[i].num=0;
        }
        while(n--)
        {
            scanf("%s",ch);
            for(flag=1,i=0;i<point;i++)
            {
                if(!strcmp(ch,ball[i].ch))
                {
                    ball[i].num++;
                    flag=0;
                    break;
                }
            }
            if(flag)
                strcpy(ball[point++].ch,ch);

        }
        for(max=i=0;i<point;i++)
        {
            if(ball[i].num>max)
            {
                max=ball[i].num;
                t_p=i;
            }
        }
        printf("%s\n",ball[t_p].ch);
    }
    return 0;
}
2010-07-21 11:56
do8do8do8
Rank: 10Rank: 10Rank: 10
来 自:沙滩
等 级:贵宾
威 望:17
帖 子:366
专家分:1845
注 册:2010-7-2
收藏
得分:0 
完了 毁了 彻底没了 这程序没救了 血压低 心电图是条直线 左胳膊和右胳膊挤在一堆了 救不了了

学C语言从底层开始,学编程从问题开始,一日学会C!!!
2010-07-21 12:19
flyingcat
Rank: 4
来 自:HDU
等 级:业余侠客
威 望:2
帖 子:55
专家分:230
注 册:2010-7-18
收藏
得分:0 
- -!看了下,还调试了下…没明白什么情况 ,楼主能注释一下再贴回来么……
2010-07-21 12:57
编程探索者
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2010-7-21
收藏
得分:0 
我就是想用类似选择法的比较,用一个字符数组存储暂时个数最多的啊
2010-07-21 14:12
快速回复:请大牛看看我哪错了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022347 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved