344 Problem

All about problems in Volume III. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

344 Problem

Postby wamorimjr » Wed Oct 08, 2003 5:15 am

People,
I have a problem with the 344. I submited it but I received a wrong answer mail. I tried a input file with all numbers between 1 an 100 and it seems to be right.
Could someone help me. The code is above:


[code][c]
/*@BEGIN_OF_SOURCE_CODE
/* @JUDGE_ID: 32478CA 344 C */


#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>

/*---------------------------------------------------*/
/* Obtem a quantidade de cada algarismo romano nas */
/* seguintes posi
wamorimjr
New poster
 
Posts: 4
Joined: Wed Oct 08, 2003 4:50 am

Postby UFP2161 » Wed Oct 08, 2003 7:43 am

The only thing different from your output and my AC ouput is that I have an extra newline at the end of the file. Should be PE, but hey, who knows?
User avatar
UFP2161
A great helper
 
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm

Re: 344 Problem

Postby WAandAC » Sun Jun 01, 2008 8:08 pm

Why WA? I have already checked several outputs.
Code: Select all
#include <iostream>
using namespace std;
int main ()
{
   int s1[101];
   int s5 [101];
   int s10[101];
   int s50 [101];
   int s100 [101];
   
   s1 [1] = 1;
   s5 [1] = 0;
   s10 [1] = 0;
   s50 [1] = 0;
   s100 [1] = 0;

   for (int i = 2; i <= 100; i++)
   {
      if (i%10 == 1 || i%10 == 2|| i %10 == 3||
                i%10 == 6 || i%10 ==7
             || i%10 ==8)
      {
         s1 [i] = s1[i-1] + 1;
         s5 [i] = s5 [i-1];
         s10 [i] = s10 [i-1];
         s50 [i] = s50 [i-1];
         s100 [i] = s100 [i-1];

      }else if (i%10 == 4)
      {
         s1 [i] = s1[i-1] - 2;
         s5 [i] = s5 [i-1] + 1;
         s10 [i] = s10 [i-1];
         s50 [i] = s50 [i-1];
         s100 [i] = s100 [i-1];
      }else if (i%10 == 5)
      {
         s1 [i] = s1[i-1] - 1;
         s5 [i] = s5 [i-1];
         s10 [i] = s10 [i-1];
         s50 [i] = s50 [i-1];
         s100 [i] = s100 [i-1];
      }else if (i%10 == 9)
      {   s1 [i] = s1[i-1] - 2;
         s5 [i] = s5 [i-1] - 1;
         s10 [i] = s10 [i-1] + 1;
         s50 [i] = s50 [i-1];
         s100 [i] = s100 [i-1];
      }else if (i%10 == 0)
      {
         if (i<=30 || (i >= 60 && i <= 80) )
         {
            s1 [i] = s1[i-1] - 1;
            s5 [i] = s5 [i-1] ;
            s10 [i] = s10 [i-1];
            s50 [i] = s50 [i-1];
            s100 [i] = s100 [i-1];
         }else if  (i == 40)
         {
            s1 [i] = s1[i-1] - 1;
            s5 [i] = s5 [i-1] ;
            s10 [i] = s10 [i-1] - 3;
            s50 [i] = s50 [i-1] + 1;
            s100 [i] = s100 [i-1];
         }else if  (i == 50)
         {
            s1 [i] = s1[i-1] - 1;
            s5 [i] = s5 [i-1] ;
            s10 [i] = s10 [i-1] - 2;
            s50 [i] = s50 [i-1] ;
            s100 [i] = s100 [i-1];

         }else if  (i == 90)
         {
            s1 [i] = s1[i-1] - 1;
            s5 [i] = s5 [i-1] ;
            s10 [i] = s10 [i-1] - 3;
            s50 [i] = s50 [i-1] - 1;
            s100 [i] = s100 [i-1] + 1;
         }else if  ( i = 100)
         {
            s1 [i] = 0;
            s5 [i] = 0;
            s10 [i] = 0;
            s50 [i] = 0;
            s100 [i] = 1;
         }

      }      
   }

   int t1[101];
   int t5 [101];
   int t10[101];
   int t50 [101];
   int t100 [101];
   
   t1 [1] = 0;
   t5 [1] = 0;
   t10 [1] = 0;
   t50 [1] = 0;
   t100 [1] = 0;

   for ( int  i = 1; i <= 100;i++)
   {
      t1 [i] = t1[i-1] + s1[i];
      t5 [i] = t5[i-1] + s5[i];
      t10 [i] = t10[i-1] + s10[i];
      t50 [i] = t50[i-1] + s50[i];
      t100 [i] = t100[i-1] + s100[i];
   }
   int val = -1;
   while (scanf("%d", &val) == 1)
   {
      if (val == 0)break;
      printf ("%d: %d i, %d v, %d x, %d l, %d c\n", val, t1[val], t5[val], t10[val], t50[val], t100[val]);
   }
   return 0;
}

WAandAC
New poster
 
Posts: 4
Joined: Sat Nov 03, 2007 4:32 am

Re: 344 Problem

Postby valkov » Sun May 08, 2011 6:30 pm

Just got AC on this one :)
Here is a neat way to convert decimal to roman numbers:

Code: Select all
const string romanOneToNine[] = {"", "A", "AA", "AAA", "AB", "B", "BA", "BAA", "BAAA", "AC"};
const string romanDigits[] = {"IVX", "XLC", "CDM", "M" };

string GetRomanDigit(unsigned num, unsigned power)
{
    string result = "";
    string digit = romanOneToNine[num];
    for(unsigned i = 0; i < digit.size(); i++) {
        result.push_back(romanDigits[power][digit[i] - 'A']);
   }
    return result;
}

string DecimalToRoman(unsigned num)
{
    unsigned power;
    string result = "";
    for (power = 0; num > 0; power++, num /= 10) {
        result.insert(0, GetRomanDigit(num % 10, power));
    }
    return result;
}
valkov
New poster
 
Posts: 20
Joined: Tue Jul 20, 2010 3:11 pm


Return to Volume III

Who is online

Users browsing this forum: No registered users and 1 guest