| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 512 人关注过本帖
标题:一道“马甲”问题,自己测试了很多样例都没问题,但soj就是WA,求破~
只看楼主 加入收藏
Mayuri
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2012-12-17
结帖率:100%
收藏
已结贴  问题点数:4 回复次数:7 
一道“马甲”问题,自己测试了很多样例都没问题,但soj就是WA,求破~
首先声明,绝对不是求作业~
================================================
Description
    On BBS, there is a familiar term called MJ (short for MaJia), which means another BBS ID of one person besides his/her main ID.
These days, a lot of ACMers pour water on the ACMICPC Board of argo. Mr. Guo is very angry about that and he wants to punish these guys. ACMers are all smart boys/girls, right? They usually use their MJs while pouring water, so Mr. Guo can not tell all the IDs apart.  Unfortunately, the IP can not be changed, i.e, the posts of main ID and MJ of the same person has the same IP address, meanwhile, the IP addresses of different person is different.  Assuming that each person has exactly one main ID and one MJ, by reading their posts on BBS, you then tell Mr. Guo whom each MJ belongs to.

Input
    The first line of each test cases is an even integer n (0<=n<=20), the number of posts on BBS.
Then n lines follow, each line consists of two strings:
BBS_ID IP_Address
BBS_ID means the ID who posts this post. BBS_ID is a string contains only lower case alphabetical characters and its length is not greater than 12. Each BBS ID appears only once in each test cases.
IP_Address is the IP address of that person. The IP address is formatted as “A.B.C.D”, where A, B, C, D are integers ranging from 0 to 255.
It is sure that there are exactly 2 different BBS IDs with the same IP address. The first ID appears in the input is the main ID while the other is the MJ of that person.
Your program should be terminated by n = 0.

Output
    For each test case, output n/2 lines of the following format: “MJ_ID is the MaJia of main_ID”
They should be displayed in the lexicographical order of the main_ID.
Print a blank line after each test cases.
See the sample output for more details.

Sample Input
8
inkfish 192.168.29.24
zhi 192.168.29.235
magicpig 192.168.50.170
pegasus 192.168.29.235
iamcs 202.116.77.131
finalBob 192.168.29.24
tomek 202.116.77.131
magicduck 192.168.50.170
4
mmmmmm 172.16.72.126
kkkkkk 192.168.49.161
llllll 192.168.49.161
nnnnnn 172.16.72.126
0


Sample Output
tomek is the MaJia of iamcs
finalBob is the MaJia of inkfish
magicduck is the MaJia of magicpig
pegasus is the MaJia of zhi
 
llllll is the MaJia of kkkkkk
nnnnnn is the MaJia of mmmmmm

============================================
这是本人的代码:
程序代码:
#include<stdio.h>
#include<string.h>
#define SIZE 100

int main()
{
    int n,i,j,k,l,r,s;

    while(scanf("%d",&n)&&n!=0)
    {
        struct MaJia
        {
            char name[12];
            char id[SIZE];
        };
        struct MaJia a[SIZE],temp1,temp2,majia[SIZE],main_ID[SIZE];
        l = 0;

        for(i = 0; i < n; i++)
        {
            scanf("%s %s",&a[i].name,&a[i].id);
        }

        for(i = 0; i < n; i++)
        {
            for( k = 1; k < n; k++)
            {
                j = strcmp(a[i].id,a[i+k].id);
                if(j==0)
                {
                    majia[l] = a[i+k];
                    main_ID[l] = a[i];
                    l++;
                }
            }
        }


        for(s = 0; s < l-1; s++)
        {
            for(r = 0; r < l-s-1; r++)
            {
                if(strcmp(main_ID[r].name,main_ID[r+1].name) > 0)
                {
                    temp1 = main_ID[r];
                    main_ID[r] = main_ID[r+1];
                    main_ID[r+1] = temp1;

                    temp2 = majia[r];
                    majia[r] = majia[r+1];
                    majia[r+1] = temp2;
                }

            }
        }

        for(i = 0; i < l; i++)
        {
            if(i==l-1)
                printf("%s is the MaJia of %s\n\n",majia[i].name,main_ID[i].name);
            else
                printf("%s is the MaJia of %s\n",majia[i].name,main_ID[i].name);
        }
    }
    return 0;
}                                 

=========================================================
在线等......
搜索更多相关主题的帖子: usually familiar another person called 
2012-12-28 12:45
w527705090
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:441
专家分:1882
注 册:2011-6-28
收藏
得分:0 
"但soj就是WA"楼主这指的是什么意思?

有心者,千方百计;无心者,千难万难。
2012-12-28 16:30
Mayuri
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2012-12-17
收藏
得分:0 
回复 2楼 w527705090
soj是我们学校的在线测试系统,WA就是wrong answer啊
2012-12-29 02:15
conan8732
Rank: 2
等 级:论坛游民
帖 子:24
专家分:43
注 册:2012-8-8
收藏
得分:2 
("%s %s",&a[i].name,&a[i].id)  结构体里面你定义的是CHAR型  这里用%s
2012-12-29 09:11
Mayuri
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2012-12-17
收藏
得分:0 
char id[SIZE]是定義字符數組啊,字符數組讀取不是%s?
2012-12-29 09:22
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:2 
%s 是字符串(或者字符数组)
%c 才是单个字符

DO IT YOURSELF !
2012-12-29 10:41
Mayuri
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2012-12-17
收藏
得分:0 
我改为%c试试看行不行先~
2012-12-29 15:24
快速回复:一道“马甲”问题,自己测试了很多样例都没问题,但soj就是WA,求破~
数据加载中...
 
   



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

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