Sunday, July 31, 2016

Published July 31, 2016 by with 0 comment

UVA 10295 - Hay Points Solution

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<map>

using namespace std;

int main()
{
    int m,n,doller;
    map <string,int> msi;
    string word;
    scanf("%d%d",&m,&n);
    while (m--)
    {
        getchar();
        cin>>word>>doller;
        msi[word]=doller;
    }
    while (n--)
    {
        long long int points=0;
        while (cin>>word)
        {
            if (word==".") break;
            if (msi.find(word)!=msi.end()) points+=msi[word];
        }
        printf("%lld\n",points);
    }
    return 0;
}
Read More
      edit

Friday, July 29, 2016

Published July 29, 2016 by with 0 comment

UVA 484 - The Department of Redundancy Department Solution

#include<cstdio>
#include<vector>
#include<map>
using namespace std;

int main()
{
    int n;
    vector<int> v;
    map<int ,int> freq;
    while (scanf("%d",&n)!=EOF)
    {
        if (freq[n]==0) v.push_back(n);
        freq[n]=freq[n]+1;
    }
    int l=v.size();
    for (int i=0;i<l;i++)
        printf("%d %d\n",v[i],freq[v[i]]);
    return 0;
}
Read More
      edit

Friday, July 22, 2016

Published July 22, 2016 by with 0 comment

UVA 13012: Identifying tea -Solution

#include<stdio.h>
int main ()
{
    int t,i,n,c;
    while (scanf("%d",&t)==1)
    {
        i=5;
        n=0;
        while (i--)
        {
            scanf("%d",&c);
            if (c==t) n++;
        }
        printf("%d\n",n);
    }
    return 0;
}
Read More
      edit
Published July 22, 2016 by with 0 comment

UVA 12531 Solution

#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
 int angle,mark[200]={0};
 for (int i=0;i<12;i++)
 {
  for (int j=0;j<60;j++)
  {
   angle=abs(j-(i+j/12))*6;
   if (angle>180) angle=360-angle;
   mark[angle]=1;
  }
 }
 int n;
 while (scanf("%d",&n)!=EOF)
 {
  if (mark[n]) printf("Y\n");
  else printf("N\n");
 }
 return 0;
}
Read More
      edit

Wednesday, July 20, 2016

Published July 20, 2016 by with 0 comment

UVA 13059 Solution

#include<cstdio>
using namespace std;
int main()
{
    long long int  n;
    while (scanf("%lld",&n)!=EOF)
        printf("%lld\n",n-1);
    return 0;
}
Read More
      edit
Published July 20, 2016 by with 0 comment

UVA 13025 Solution

#include<cstdio>
using namespace std;
int main()
{
    printf("May 29, 2013 Wednesday\n");
    return 0;
}
Read More
      edit
Published July 20, 2016 by with 0 comment

UVA 12992 Solution

#include<cstdio>
using namespace std;
int main()
{
    int n,tc,c=1;
    scanf("%d",&tc);
    while (tc--)
    {
        scanf("%d",&n);
        printf("Case #%d: %d\n",c++,2*n-1);
    }
    return 0;
}
Read More
      edit
Published July 20, 2016 by with 0 comment

UVA 12895 Solution

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

int main()
{
    int tc;
    scanf("%d",&tc);
    getchar();
    while (tc--)
    {
        char s[15];
        gets(s);
        int b,l=strlen(s);
        long long int n,a;
        n=a=0;
        for (int i=0;i<l;i++)
        {
            b=s[i]-'0';
            a+=pow(b,l);
            n=n*10+b;
        }
        if (a==n) printf("Armstrong\n");
        else printf("Not Armstrong\n");
    }
    return 0;
}
Read More
      edit
Published July 20, 2016 by with 0 comment

uva 12700 solution

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

int main()
{
    int tc,nc=1;
    scanf("%d",&tc);
    while (tc--)
    {
        int n,b,w,t,a;
        char s[15];
        scanf("%d",&n);
        getchar();
        gets(s);
        b=w=t=a=0;
        for (int i=0;i<n;i++)
        {
            if (s[i]=='B') b++;
            else if (s[i]=='W') w++;
            else if (s[i]=='T') t++;
            else if (s[i]=='A') a++;
        }
        printf("Case %d: ",nc++);
        if((b+a==n)&& b!=0)
            printf("BANGLAWASH\n");
        else if((w+a==n) && w!=0)
            printf("WHITEWASH\n");
        else if(a==n)
            printf("ABANDONED\n");
        else if(b>w)
            printf("BANGLADESH %d - %d\n",b,w);
        else if(b<w)
            printf("WWW %d - %d\n",w,b);
        else if(b==w)
            printf("DRAW %d %d\n",b,t);
    }
    return 0;
}
Read More
      edit
Published July 20, 2016 by with 0 comment

uva 12626 solution

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

int main()
{
    int tc,nc=1;
    scanf("%d",&tc);
    while (tc--)
    {
        int n,b,w,t,a;
        char s[15];
        scanf("%d",&n);
        getchar();
        gets(s);
        b=w=t=a=0;
        for (int i=0;i<n;i++)
        {
            if (s[i]=='B') b++;
            else if (s[i]=='W') w++;
            else if (s[i]=='T') t++;
            else if (s[i]=='A') a++;
        }
        printf("Case %d: ",nc++);
        if((b+a==n)&& b!=0)
            printf("BANGLAWASH\n");
        else if((w+a==n) && w!=0)
            printf("WHITEWASH\n");
        else if(a==n)
            printf("ABANDONED\n");
        else if(b>w)
            printf("BANGLADESH %d - %d\n",b,w);
        else if(b<w)
            printf("WWW %d - %d\n",w,b);
        else if(b==w)
            printf("DRAW %d %d\n",b,t);
    }
    return 0;
}
Read More
      edit
Published July 20, 2016 by with 0 comment

uva 12611 solution

#include<cstdio>
using namespace std;
int main()
{
    int tc,c=1;
    scanf("%d",&tc);
    while (tc--)
    {
        int r,len,wide;
        scanf("%d",&r);
        len=r*5;
        wide=len*60/100;
        int x1=len*45/100;
        int x2=len*55/100;
        int y=wide/2;
        printf("Case %d:\n-%d %d\n%d %d\n%d -%d\n-%d -%d\n",c++,x1,y,x2,y,x2,y,x1,y);
    }
    return 0;
}
Read More
      edit
Published July 20, 2016 by with 0 comment

uva 12478 solution

#include<cstdio>
using namespace std;
int main()
{
    printf("KABIR\n");
    return 0;
}
Read More
      edit
Published July 20, 2016 by with 0 comment

uva 12461 solution

#include<cstdio>
using namespace std;
int main()
{
    int n;
    while (scanf("%d",&n) && n)
    printf("1/2\n");
    return 0;
}
Read More
      edit
Published July 20, 2016 by with 0 comment

uva 12459 solution

#include<cstdio>
using namespace std;
typedef unsigned long long llu;

llu f[90]={0};
llu fib(int n)
{
    if (n<4) f[n]=n;
    if (f[n]==0) f[n]=fib(n-2)+fib(n-1);
    return f[n];
}

int main()
{
    int n;
    while (scanf("%d",&n)&& n)
    printf("%llu\n",fib(n));
    return 0;
}
Read More
      edit
Published July 20, 2016 by with 0 comment

uva 12342 solution

#include<cstdio>
#include<cmath>
using namespace std;

int main()
{
    int tc,c=1;
    scanf("%d",&tc);
    while (tc--)
    {
        double income,tax=0;
        scanf("%lf",&income);
        income-=180000;
        if (income>300000)
        {
            tax+=300000*0.10;
            income-=300000;
        }
        else if (income>0)
        {
            tax+=income*0.10;
            goto print;
        }
        if (income>400000)
        {
            tax+=400000*0.15;
            income-=400000;
        }
        else if (income>0)
        {
            tax+=income*0.15;
            goto print;
        }
        if (income>300000)
        {
            tax+=300000*0.20;
            income-=300000;
        }
        else if (income>0)
        {
            tax+=income*0.20;
            goto print;
        }
        if (income>0)
        {
            tax+=income*0.25;
            goto print;
        }
        print:
        int ans=ceil(tax);
        if (ans<2000 && ans>0) ans=2000;
        printf("Case %d: %d\n",c++,ans);
    }
    return 0;
}
Read More
      edit
Published July 20, 2016 by with 0 comment

uva 12243 solution

#include<cstdio>
#include<cstring>
#include<set>
#include<cctype>
using namespace std;

int main()
{
    char s[5000];
    while (gets(s))
    {
        if (!strcmp(s,"*")) return 0;
        int t=1;
        int l=strlen(s);
        set < char > cs;
        for (int i=0;i<l;i++)
        {
            if (s[i]==' ') t=1;
            if (t && s[i]!=' ')
            {
                cs.insert(tolower(s[i]));
                t=0;
            }
        }
        if (cs.size()==1) printf("Y\n");
        else printf("N\n");
    }
    return 0;
}
Read More
      edit

Tuesday, July 19, 2016

Published July 19, 2016 by with 0 comment

uva 12136 solution

#include<cstdio>
using namespace std;
int main()
{
    int tc,c=1;
    scanf("%d",&tc);
    while (tc--)
    {
        int h,m,wstart,wend,mstart,mend;
        scanf("%d:%d",&h,&m);
        wstart=h*100+m;
        scanf("%d:%d",&h,&m);
        wend=h*100+m;
        scanf("%d:%d",&h,&m);
        mstart=h*100+m;
        scanf("%d:%d",&h,&m);
        mend=h*100+m;
        if (mend<wstart || mstart>wend) printf("Case %d: Hits Meeting\n",c++);
        else printf("Case %d: Mrs Meeting\n",c++);
    }
    return 0;
}
Read More
      edit
Published July 19, 2016 by with 0 comment

uva 11934 solution

#include<cstdio>
#include<cmath>
using namespace std;

int main()
{
    int a,b,c,d,l,cnt;
    while (scanf("%d%d%d%d%d",&a,&b,&c,&d,&l)==5)
    {
        if (!a && !b && !c && !d && !l) return 0;
        cnt=0;
        for (int i=0;i<=l;i++)
            if ((a*i*i+b*i+c)%d==0) cnt++;
        printf("%d\n",cnt);
    }
    return 0;
}
Read More
      edit
Published July 19, 2016 by with 0 comment

uva 11900 solution

#include<cstdio>
using namespace std;

int main()
{
    int tc,c=1;
    scanf("%d",&tc);
    while (tc--)
    {
        int n,p,q,w[30],i,s=0;
        scanf("%d%d%d",&n,&p,&q);
        for (i=0;i<n;i++) scanf("%d",&w[i]);
        for (i=0;i<n && i<p;i++)
        {
            s+=w[i];
            if (s>q) break;
        }
        printf("Case %d: %d\n",c++,i);
    }
    return 0;
}
Read More
      edit
Published July 19, 2016 by with 0 comment

uva 11734 solution

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

int main()
{
    int tc,c=1;
    scanf("%d",&tc);
    getchar();
    while (tc--)
    {
        char s1[1000],s2[1000];
        gets(s1);
        gets(s2);
        if (!strcmp(s1,s2)) printf("Case %d: Yes\n",c++);
        else
        {
            char s3[1000];
            int l=strlen(s1);
            int k=-1;
            for (int i=0;i<l;i++)
                if (s1[i]!=' ') s3[++k]=s1[i];
            s3[++k]='\0';
            if (!strcmp(s2,s3)) printf("Case %d: Output Format Error\n",c++);
            else printf("Case %d: Wrong Answer\n",c++);
        }
    }
    return 0;
}
Read More
      edit