Wednesday, July 20, 2016

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