URI ONLINE JUDGE SOLUTION 1307 - Online Judge

Latest

This is an Online Judge Solution Base Site. We can discuss & Solve any contest solution in Programming.

Friday, April 10, 2020

URI ONLINE JUDGE SOLUTION 1307

Problem Number: 1307
Problem Name: All You Need Is Love
Author’s Name: Maratona de Programação da SBC 2001* Brazil
Timelimit: 1
Problem Category: AD-HOC
Problem Source: https://www.urionlinejudge.com.br/judge/en/problems/view/1307

Solution:

#include <cstdio>
#include <cstring>

using namespace std;

int binToDec(char a[])
{
    int m = a[0] - '0', sz = strlen(a);

    for(int i = 1; i < sz; i++)
    {
        m *= 2;
        m += (a[i] - '0');
    }

    return m;
}

int GCD(int a, int b)
{
    if(b > a)
        return GCD(b, a);
   
    if(b == 0) return a;
    else return GCD(b, a % b);
}

int main(int argc, char const *argv[])
{
    int n, sx, sy, r;
    char s1[32], s2[32];

    scanf("%dn", &n);

    for(int i = 1; i <= n; i++)
    {
        gets(s1); gets(s2);
   
        sx = binToDec(s1); sy = binToDec(s2);
   
        r = GCD(sx, sy);
   
        if(r != 1) printf("Pair #%d: All you need is love!n", i);
        else printf("Pair #%d: Love is not all you need!n", i);
    }

    return 0;
}

No comments:

Post a Comment

Thanks..