Sunday, March 2, 2014

UVa 10235 - Simply Emirp solution

Problem link :  UVa 10235 - Simply Emirp

Solution : 


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
int prime(long long int n)
{
    int i,j;
    if(n==1)
    return 0;

    if(n==2)
    return 1;

    if(n%2==0)
    return 0;

    int l=sqrt(n);

    for(i=3;i<=l;i+=2)
    {
        if(n%i==0)
        return 0;
    }
    return 1;
}
int main()
{
    long long int n,i,j,m,sum;
    while(scanf("%lld",&n)==1)
    {

        i=0; j=0; sum=0;

        if(prime(n))
            i=1;

        if(i==1)
        {
            m=n;

            while(m!=0)
            {
                sum=((sum*10)+(m%10));
                m/=10;
            }

            if(prime(sum))
            j=1;
        }

        if(j==1 && n!=sum)
            printf("%lld is emirp.\n",n);
        else if(i==1)
            printf("%lld is prime.\n",n);
        else
            printf("%lld is not prime.\n",n);
    }
    return 0;
}




UVa 10222 - Decode the Mad Man solution

Problem link :  UVa 10222 - Decode the Mad Man

Solution : 


#include<stdio.h>
#include<string.h>
int main()
{
    char a[10005];
    int i,l;
    while(gets(a))
    {
        l=strlen(a);
        for(i=0;i<l;i++)
        {
            if(a[i]==']')
                a[i]='p';
            else if(a[i]=='[')
                a[i]='o';
            else if(a[i]=='p' || a[i]=='P')
                a[i]='i';
            else if(a[i]=='o' || a[i]=='O')
                a[i]='u';
            else if(a[i]=='i' || a[i]=='I')
                a[i]='y';
            else if(a[i]=='u' || a[i]=='U')
                a[i]='t';
            else if(a[i]=='y' || a[i]=='Y')
                a[i]='r';
            else if(a[i]=='t' || a[i]=='T')
                a[i]='e';
            else if(a[i]=='r' || a[i]=='R')
                a[i]='w';
            else if(a[i]=='e' || a[i]=='E')
                a[i]='q';

            else if(a[i]=='\'')
                a[i]='l';
            else if(a[i]==';')
                a[i]='k';
            else if(a[i]=='l' || a[i]=='L')
                a[i]='j';
            else if(a[i]=='k' || a[i]=='K')
                a[i]='h';
            else if(a[i]=='j' || a[i]=='J')
                a[i]='g';
            else if(a[i]=='h' || a[i]=='H')
                a[i]='f';
            else if(a[i]=='g' || a[i]=='G')
                a[i]='d';
            else if(a[i]=='f' || a[i]=='F')
                a[i]='s';
            else if(a[i]=='d' || a[i]=='D')
                a[i]='a';

            else if(a[i]=='/')
                a[i]=',';
            else if(a[i]=='.')
                a[i]='m';
            else if(a[i]==',')
                a[i]='n';
            else if(a[i]=='m' || a[i]=='M')
                a[i]='b';
            else if(a[i]=='n' || a[i]=='N')
                a[i]='v';
            else if(a[i]=='b' || a[i]=='B')
                a[i]='c';
            else if(a[i]=='v' || a[i]=='V')
                a[i]='x';
            else if(a[i]=='c' || a[i]=='C')
                a[i]='z';

            else if(a[i]=='=')
                a[i]='0';
            else if(a[i]=='-')
                a[i]='9';
            else if(a[i]=='0')
                a[i]='8';
            else if(a[i]=='9')
                a[i]='7';
            else if(a[i]=='8')
                a[i]='6';
            else if(a[i]=='7')
                a[i]='5';
            else if(a[i]=='6')
                a[i]='4';
            else if(a[i]=='5')
                a[i]='3';
            else if(a[i]=='4')
                a[i]='2';
            else if(a[i]=='3')
                a[i]='1';
            else if(a[i]=='2')
                a[i]='`';
        }
        puts(a);
    }
    return 0;
}




UVa 10195 - The Knights Of The Round Table solution

Problem link :  UVa 10195 - The Knights Of The Round Table

Solution : 


#include<stdio.h>
#include<math.h>
int main()
{
    double a,b,c,i,r;
    while(scanf("%lf %lf %lf",&a,&b,&c)==3)
    {
        if(a<=0||b<=0||c<=0)
            printf("The radius of the round table is: 0.000\n");
        else
        {
            i=(a+b+c)/2;
            r=sqrt((i-a)*(i-b)*(i-c)/i);
            printf("The radius of the round table is: %.3lf\n",r);
        }
    }
    return 0;
}




UVa 10110 - Light more light solution

Problem link :  UVa 10110 - Light more light

Solution : 


#include<stdio.h>
#include<math.h>
int main()
{
    long long int n,a,i;
    while(scanf("%lld",&n)==1)
    {
        if(n==0)
            break;
        i=sqrt(n);
        a=i*i;
        if(a==n)
            printf("yes\n");
        else
            printf("no\n");
    }
    return 0;
}




UVa 10082 - WERTYU solution

Problem link :  UVa 10082 - WERTYU

Solution : 


#include<bits/stdc++.h>
using namespace std;

char a[]={"`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./"};

char f(char c)
{
    for(int i=0;i<47;i++)
    {
        if(a[i]==c) return a[i-1];
    }
    return c;
}

int main()
{
    char s[10005];
    while(gets(s))
    {
        int l=strlen(s);
        for(int i=0;i<l;i++) s[i]=f(s[i]);
        puts(s);
    }
    return 0;
}