UVA Easy Problem's Solution

UVA 100 3n+1


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,j,k,l,n,m,c,maxi,a,b;
    vector<long long int>v;
    //freopen("100in.txt","r",stdin);
    //freopen("100out.txt","w",stdout);
    while(cin>>n>>m)
    {

        v.clear();
        maxi=0;
        a=n;
        b=m;

        if(n>m)
        {
            swap(n,m);
        }

        for(i=n;i<=m;i++)
        {
          c=1;
          l=i;
          while(l!=1)
          {
            if(l%2==0)
            {
                l=l/2;
                c++;
            }
            else if(l==1)
            {
                c++;
                break;
            }
            else
            {
                l=3*l+1;
                c++;
            }
          }
          //cout<<i<<c<<endl;
          v.push_back(c);

        }
        for(j=0;j<v.size();j++)
        {
            if(v[j]>maxi)
            {
                maxi=v[j];
            }
        }

        cout<<a<<" "<<b<<" "<<maxi<<endl;
    }

    return 0;
}



UVA-458 (The Decoder)

#include <stdio.h>
#include <string.h>
int main()
{
    char a[100];
    int i;
    while(gets(a))
    {
        for(i=0;i<strlen(a);i++)
        {
            printf("%c",a[i]-7);
        }
        printf("\n");
    }
    return 0;
}
 

UVA-10071 (Back To High School Physics)

#include <stdio.h>
int main()
{
    int a,b;
    while(scanf("%d %d",&a,&b)!=EOF)
    {
        printf("%d\n",a*b*2);
    }
    return 0;
}

UVA-10783 (Odd Sum)

#include <stdio.h>
int main()
{

    int n,i,a,b,sum,j;
    while(scanf("%d",&n)!=EOF)
    {
        for(j=1;j<=n;j++)
        {
          sum=0;
         scanf("%d%d",&a,&b);
        for(i=a;i<=b;i++)
        {
            sum=0;

                for(i=a;i<=b;i++)
                {
                    if((i%2)!=0)
                    {
                    sum=sum+i;
                    }
                }
            }
            printf("Case %d: %d\n",j,sum);
        }
    }
    return 0;
}






UVA-10055 (Hasmat The Brave Warrior)

#include <stdio.h>
int main()
{
    long long int a,b,c;
    while(scanf("%lld %lld",&a,&b)!=EOF)
    {
        if(a>b)
            c=a-b;
        else
            c=b-a;
        printf("%lld",c);
    }
    return 0;
}

UVA-10082 (WERTYU)

#include<stdio.h>
int main()
{
    char c;
    while (scanf("%c",&c)==1)
    {
        if (c=='1')
            printf("`");
        else if (c=='2')
            printf("1");
        else if (c=='3')
            printf("2");
        else if (c=='4')
            printf("3");
        else if (c=='5')
            printf("4");
        else if (c=='6')
            printf("5");
        else if (c=='7')
            printf("6");
        else if (c=='8')
            printf("7");
        else if (c=='9')
            printf("8");
        else if (c=='0')
            printf("9");
        else if (c=='-')
            printf("0");
        else if (c=='=')
            printf("-");
        else if (c=='W')
            printf("Q");
        else if (c=='E')
            printf("W");
        else if (c=='R')
            printf("E");
        else if (c=='T')
            printf("R");
        else if (c=='Y')
            printf("T");
        else if (c=='U')
            printf("Y");
        else if (c=='I')
            printf("U");
        else if (c=='O')
            printf("I");
        else if (c=='P')
            printf("O");
        else if (c=='[')
            printf("P");
        else if (c==']')
            printf("[");
        else if (c=='\\')
            printf("]");
        else if (c=='S')
            printf("A");
        else if (c=='D')
            printf("S");
        else if (c=='F')
            printf("D");
        else if (c=='G')
            printf("F");
        else if (c=='H')
            printf("G");
        else if (c=='J')
            printf("H");
        else if (c=='K')
            printf("J");
        else if (c=='L')
            printf("K");
        else if (c==';')
            printf("L");
        else if (c=='\'')
            printf(";");
        else if (c=='X')
            printf("Z");
        else if (c=='C')
            printf("X");
        else if (c=='V')
            printf("C");
        else if (c=='B')
            printf("V");
        else if (c=='N')
            printf("B");
        else if (c=='M')
            printf("N");
        else if (c==',')
            printf("M");
        else if (c=='.')
            printf(",");
        else if (c=='/')
            printf(".");
        else if (c==' ')
            printf(" ");
        else if (c=='\n')
            printf("\n");
    }
    return 0;
}
 

UVA-11172 (Relational Operators)

#include <stdio.h>
int main()
{
    int i,n,a,b;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=0;i<n;i++)
        {
            scanf("%d %d",&a,&b);
            if(a>b)
                printf(">\n");
            else if(a<b)
                printf("<\n");
            else
                printf("=\n");

        }
    }
    return 0;
}

UVA-11044 (Searching For Nessy)

#include <stdio.h>
int main()
{
    int t,n,m,i;
    while(scanf("%d",&t)!=EOF)
    {
        for(i=1;i<=t;i++)
        {
          scanf("%d %d",&n,&m);
          printf("%d\n",((n/3)*(m/3)));
        }
    }
    return 0;
}





UVA-494 (Kintergarden Counting)

#include <stdio.h>
int main()
{
    char a[100],i;
    while(gets(a))
    {
        int sum=0,t=1;
        for(i=0;i<strlen(a);i++)
        {
            if(a[i]>='A' && a[i]<='Z' || a[i]>='a' && a[i]<='z')
            {
                if(t)
                sum=sum+1;
                t=0;
            }
            else
                t=1;
        }
        printf("%d\n",sum);
    }
    return 0;
}
 


Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment