注册 登录
编程论坛 C++教室

poj1013

酷爱陈阳 发布于 2015-01-16 18:44, 537 次点击
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    char left[3][5];
    char right[3][5];
    char status[3][5];
    int n;
    cin>>n;
    getchar();
    while(n--)
    {
        int i;
        for(i=0;i<3;i++)
        {
            scanf("%s",left[i]);
            scanf("%s",right[i]);
            gets(status[i]);
        }
        int x;
        int t;
        for(x='A';x<='L';x++)
        {
            int wl=0;
            int wr=0;
            int j;
            int tag;
            int flag[3][3]={0};
            for(i=0;i<3;i++)
            {
                if(status[i][0]=='e')
                    tag=0;
                else if(status[i][0]=='u')
                    tag=1;
                else
                    tag=-1;
                t=0;
                while(t<=2)
                {
                    for(j=0;j<4;j++)
                    {
                        if(x==left[i][j])
                            wl+=t;
                        else
                            wl++;
                    }
                    for(j=0;j<4;j++)
                    {
                        if(x==right[i][j])
                            wr+=t;
                        else
                            wr++;
                    }
                    if((wl-wr)==tag)
                        flag[t][i]=1;
                    t+=2;
                    wl=0;
                    wr=0;
                }
            }
            bool print=0;
            for(j=0;j<=2;j+=2)
                if(flag[j][0]==1&&flag[j][1]==1&&flag[j][2]==1)
                {
                    if(j==0)
                        printf("%c is the counterfeit coin and it is light.",x);
                    else
                        printf("%c is the counterfeit coin and it is heavy.",x);
                    cout<<endl;
                    print=1;
                }
            if(print==1)
                break;
        }   
    }
    return 0;
}



输不出正确答案,这是哪里有错
2 回复
#2
wp2319572015-01-22 13:49
不着头脑
#3
rjsp2015-01-22 14:34
如果你自己都懒得贴出 poj1013 的话
别人也一定懒得为了你的问题去网上查
1