Algorithm


Problem Name: 2 AD-HOC - beecrowd | 1483

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1483

Animal Game

 

Por Ricardo Anido Brazil

Timelimit: 1

In a not very distant country, people are addicted on a simple bet game. The game is based in numbers and is called "Animal Game". The game received this name because the numbers are divided in 25 groups, depending of the value of the two last digits (tens and units). Each group is associated with an animal in the following form: the first group (donkey) is formed by the numbers 01, 02, 03 and 04; the second group (eagle) is formed by the numbers 05, 06, 07 and 08; and so on until the last group, formed by the numbers 97, 98, 99 and 00. The rules of he game are simple. In the moment of the bet, the player decides the value of the bet V and a number N (0 ≤ N ≤ 1000000). All the days, in the main square of the city, a number M is drawn (0 ≤ M ≤ 1000000). The prize is calculated as follows:

  • If M and N have the same four last digits (thousands, hundreds, tens and units), the bettor receives V × 3000 (for example, N = 99301 and M = 19301)
  • If M and N have the same last three digits (hundreds, tens and units), the bettor receives V × 500 (for example, N = 38944 and M = 83944)
  • If M and N have the same last two digits (tens and units), the bettor receives 50 × V (for example, N = 111 and M = 552211)
  • If M and N have the last two digits in the same group, corresponding to the same animal, the bettor receives V × 16 (for example, N = 82197 and M = 337600)
  • If none of the above occurs, the bettor don't receive any money.
  • Obviously, the award given to the bettor is the maximum possible according to the rules above. However, it is not possible to accumulate awards, so that only one of the above criteria should be applied in calculating the award. If the number N or M has less than four digits, assume that the digit 0 must be added in front of the number to make it a number of length four, for example, 17 corresponds to 0017.
  • Given the amount bet, the number chosen by the bettor and the number drawn, your program should calculate what the prize the player should receive.

 

Input

 

The input contains several test cases. Each case consists of one line containing a real number V and two integers N and M, representing respectively the amount bet with two decimal places (0.01 ≤ V ≤ 1000.00), the number chosen for the bet (0 ≤ N ≤ 1000000) and the selected number (0 ≤ M ≤ 1000000). The end of input is indicated by a line containing V = M = N = 0.

 

Output

 

For each test case your program should print a line containing a real number with two decimal places, representing the prize corresponding to the given bet.

 

 

 

Sample Input Sample Output

32.20 32 213929
10.50 32 213032
2000.00 340000 0
520.00 874675 928567
10.00 1111 578311
0 0 0

515.20
5250.00
6000000.00
0.00
500.00

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <cstdio>
int grupo[101];
int main() {
    grupo[0] = -1;
    for (int i = 1; i  < = 100; i++) {
        grupo[i] = (i - 1) / 4;
    }
    double v;
    int n, m;
    while (scanf("%lf %d %d", &v, &n, &m) && (n || m || v)) {
        if (n % 10000 == m % 10000) {
            printf("%.2lf\n", v * 3000);
        } else if (n % 1000 == m % 1000) {
            printf("%.2lf\n", v * 500);
        } else if (n % 100 == m % 100) {
            printf("%.2lf\n", v * 50);
        } else {
            if (grupo[n % 100] == grupo[m % 100]) {
                printf("%.2lf\n", v * 16);
            } else {
                printf("0.00\n");
            }
        }
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
32.20 32 213929
10.50 32 213032
2000.00 340000 0
520.00 874675 928567
10.00 1111 578311
0 0 0

Output

x
+
cmd
515.20
5250.00
6000000.00
0.00
500.00
Advertisements

Demonstration


Previous
#1478 Beecrowd Online Judge Solution 1478 Square Matrix II Solution in C++, Java, Js and Python
Next
#1486 Beecrowd Online Judge Solution 1486 Biochemical Digital Circuit Solution in C, C++, Java, Js and Python