Showing posts with label UVa online judge. Show all posts
Showing posts with label UVa online judge. Show all posts

Monday, April 03, 2017

UVa 10079 ( Pizza Cutting )

The ACM-ICPC Live Archive

UVa 10079 ( Pizza Cutting )


10079 Pizza Cutting
When someone calls Ivan lazy, he claims that it is his intelligence that helps him to be so. If his
intelligence allows him to do something at less physical effort, why should he exert more? He also
claims that he always uses his brain and tries to do some work at less effort; this is not his laziness,
rather this is his intellectual smartness.
Once Ivan was asked to cut a pizza into seven pieces to distribute it among
his friends. (Size of the pieces may not be the same. In fact, his piece will be
larger than the others.) He thought a bit, and came to the conclusion that
he can cut it into seven pieces by only three straight cuts through the pizza
with a pizza knife. Accordingly, he cut the pizza in the following way (guess
which one is Ivan’s piece):
One of his friends, who never believed in Ivan’s smartness, was startled
at this intelligence. He thought, if Ivan can do it, why can’t my computer?
So he tried to do a similar (but not exactly as Ivan’s, for Ivan will criticize
him for stealing his idea) job with his computer. He wrote a program that
took the number of straight cuts one makes through the pizza, and output a number representing the

Sunday, April 02, 2017

UVA Solution Prime words (10924)

  10924 Prime Words  UVA ONLINE JUDGE

#include<stdio.h>
#include<string.h>
#include<math.h>
char str[5000000];
int main()
{

    while(scanf("%s",str)!=EOF)
    {


    int a,b,c,d,e;
    a=strlen(str);
    for(c=0;c<a;c++)
    {
        if(str[c]>='a' && str[c]<='z')
        {
            str[c]=str[c]-96;
        }
       else if(str[c]>='A' && str[c]<='Z')
        {
            str[c]=str[c]-38;
        }
    }
    long long int result=0;
    for(c=0;c<a;c++)
    {
       result+=str[c];
    }

      int nil,bis=0;
      for(nil=1;nil<=sqrt(result);nil++)
      {

          if(result%nil==0)
          {
              bis++;
          }
      }
      if(bis==1)
      {
          printf("It is a prime word.\n");
      }
      else
        printf("It is not a prime word.\n");



}
return 0;
}

UVa Solution 10071 (Back To High School Physics)


The ACM-ICPC Live Archive

UVa 10071
(Back To High School Physics) 



Solution : 

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int v,t,i;
    for(i=1; scanf("%d %d",&v,&t)!=EOF;i++)
    {
    printf("%d\n",v*(t*2));
    }
    return 0;
}

UVa Solution 11547 - Automatic Answer


The ACM-ICPC Live Archive

                

                

            11547 - Automatic Answer





Solution : 

#include<bits/stdc++.h>
using namespace std;
int main( )
{
    int n,t,res;
    cin>>t ;
    for (int i=1;i<=t;i++)
    {
        cin>>n;
        res=((((((n*567)/9)+7492)*235)/47)-498);
        cout<<abs((res/10)%10)<<endl;
    }
    return 0;
}


Prime Words UVa 10924 problem




problem link::
https://uva.onlinejudge.org/external/109/10924.pdf




solution::

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    while(cin>>str)
    {
        long long int c=0,sum=0;
        for(int i=0;i<str.size();i++)
        {
            if(islower(str[i]))
            {
                sum+=(str[i]-'a')+1;
            }
            else
            {
                sum+=(str[i]-'A')+27;
            }
        }
        for(int j=2;j<=sqrt(sum);j++)
        {
            if(sum%j==0)
            {
                c=1;
                break;
            }
        }
        if(c==1)
        {
            cout<<"It is not a prime word."<<endl;
        }
        else
        {
            cout<<"It is a prime word."<<endl;
        }
    }
    return 0;
}

UVa Problem Solution 11462



UVa Problem 11462
Age Sort

Problem link:
https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2457



Solution : 


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

int main()
{
    long int a[2000005],i,n;
    while (scanf("%ld",&n)!=EOF)
    {
        if (n==0)
        {
            break;
        }
        for (i=0;i<n;i++)
        {
            scanf("%ld",&a[i]);
        }
        sort(a,a+n);
        for (i=0;i<n;i++)
        {
            printf("%ld",a[i]);
            if (i<(n-1))
                printf(" ");
        }
        printf("\n");
    }
    return 0;
}

UVa 11332 solution


UVa Problem 11332
Summing Digit

Problem link:
https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2307

Solution :         

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int n,sum;
    while(cin >> n, n != 0)
    {
        if (n<10)
            cout<<n<<endl;
        if (n>9)
        {
            while (n>9)
            {
                sum=0;
                while (n>0 )
                {
                    sum=sum+n%10;
                    n=n/10;
                }
                sum=n+sum;
            }
            cout<<sum<<endl;
        }
    }
    return 0;
}