2012年11月2日 星期五

Q11219: How old are you?

原文
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2160
中譯
http://luckycat.kshs.kh.edu.tw/homework/q11219.htm
#include "stdio.h"

int main()
{
  int T,D,M,Y,d,m,y,DAYS,days,times = 1;

  scanf(" %d",&T);
  while ( times <= T )
  {
 scanf(" %d/%d/%d",&D,&M,&Y); 
 scanf(" %d/%d/%d",&d,&m,&y);  

 DAYS = Y * 12 * 31 + (M - 1) * 31 + D;
 days = y * 12 * 31 + (m - 1) * 31 + d;

 if( DAYS - days < 0)
   printf("Case #%d: Invalid birth date\n",times);
 else if( DAYS - days >= 131 * 12 * 31 )
   printf("Case #%d: Check birth date\n",times);
 else
 {
   printf("Case #%d: %d\n",times,(DAYS - days) / (12 * 31));
 }
 times++;
  }
  return 0;
}

Q11204: Musical instruments

原文
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2145
中譯
http://luckycat.kshs.kh.edu.tw/homework/q11204.htm


#include "stdio.h"

int main()
{
  int num,i,j,k,total;
  scanf(" %d",&num);
  for(i = 0;i < num;i++)
  {
 int N,M,tmp,first[32]={0},times = 1;
 scanf(" %d %d",&N,&M);
 for(j = 0;j < M;j++)
 {
   for(k =0;k < N;k++)
   {
  scanf(" %d",&tmp);
  if( tmp == 1 )
    first[k] += 1;
   }
 }
 for(j = 0;j < N;j++)
 {
   if( first[j] > 0)
   {
  times *= first[j];
   }
 }
 printf("%d\n",times);
  }
  return 0;
}

Q11185: Ternary

原文
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2126
中譯
http://luckycat.kshs.kh.edu.tw/homework/q11185.htm
#include "stdio.h"

int main()
{
  int N;
  while( scanf(" %d",&N) )
  {
 int q[1000],i = 0,j;
 if( N < 0 )
   break;
 if( N == 0)
   q[0] = 0;
 while( N > 0 )
 {
   q[i] = N % 3;
   N = N / 3;
   if( N == 0 )
  break;
   i++;
 }
 for(j = i;j >= 0;j--)
 {
   printf("%d",q[j]);
 }
 printf("\n");
  }
  return 0;
}

Q11172: Relational Operators

原文
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2113
中譯
http://luckycat.kshs.kh.edu.tw/homework/q11172.htm
#include "stdio.h"

int main()
{
  int num,a,b;
  scanf(" %d",&num);
  while( num )
  {
 scanf(" %d %d",&a,&b);
 if( a > b )
   printf(">\n");
 if( a < b )
   printf("<\n");
 if( a == b )
   printf("=\n");
 num--;
  }
  return 0;
}

Q11059: Maximum Product

原文
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2000
中譯
http://luckycat.kshs.kh.edu.tw/homework/q11059.htm
#include "stdio.h"

int main()
{
  int N,S[20],num = 1;
  while( scanf(" %d",&N) != EOF && N)
  {
 int i,j,k;
 long long int P;
 for(i = 0;i < N;i++)
 {
   scanf(" %d",&S[i]);
   if(i == 0)
  P = S[i];
   else
   {
  for(j = 0;j <= i;j++)
  {
    long long int tmp = 1;
    for(k = j;k <=i;k++)
   tmp *= S[k];
    if( P < tmp )
      P = tmp;
  }
   }
 }
 if( P < 0 )
   P = 0;
    printf("Case #%d: The maximum product is %lld.\n\n",num,P);
 num++;
  }
  return 0;
}