CodeForces 47B Coins

B. Coins
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal.

Input

The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A<B.

Output

It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights.

Sample test(s)
Input
A>B
C<B
A>C
Output
CBA
Input
A<B
B>C
C>A
Output
ACB

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;

int main(){
    int num[3];
    int min,mid,max;
    char temp[10];
    memset(num,0,sizeof(num));
    for(int i=0;i<3;i++){
        cin>>temp;
        if(temp[1]=='>'){
            num[temp[0]-'A']++;
        }
        if(temp[1]=='<'){
            num[temp[2]-'A']++;
        }
    }
    if(num[0]==num[1]||num[1]==num[2]||num[2]==num[0]){
        cout<<"Impossible"<<endl;
    }
    else{
        for(int i=0;i<3;i++){
            if(num[i]==2){
                max=i;
            }
            if(num[i]==1){
                mid=i;
            }
            if(num[i]==0){
                min=i;
            }
        }
        printf("%c%c%c\n",min+'A',mid+'A',max+'A');
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值