-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhow_many_games.cpp
83 lines (61 loc) · 1.19 KB
/
how_many_games.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <cstdio>
using namespace std;
long int no_of_games( long int avg ) {
int sol = 0;
int exp = 0;
while( avg % 10000 != 0 ) {
long int lst_dgt = 0;
for ( int i = 1; i <=4; i++ ) {
long int div = pow(10, i);
if ( avg % div != 0 ) {
lst_dgt = ( ( avg % div ) / (div / 10) ) ;
break;
}
}
cout << " last digit " << lst_dgt << endl;
getchar();
long int d;
if ( lst_dgt % 2 == 0 ) {
d = 5;
} else if ( lst_dgt == 1 || lst_dgt == 3 || lst_dgt == 7 || lst_dgt == 9 ) {
d = 0;
} else if ( lst_dgt == 5 ) {
d = 2;
}
sol += d * pow(10, exp);
if (
avg = avg * d * pow(10, exp);
exp++;
}
return sol;
}
int main()
{
int t;
cin >> t;
for ( int i = 0; i < t; i++ ) {
char ch = 'a';
while ( ch != '.' ) {
cin >> ch;
}
string s = "0000";
int j = 0;
ch = getchar();
while ( ch != '\n' ) {
s[j] = ch;
ch = getchar();
j++;
}
long int avg = 1000 * (s[0] - 48) + 100 * (s[1] - 48) + 10* (s[2]- 48) + 1 * (s[3] - 48);
if ( avg == 0 ) {
cout << 0 << endl;
} else {
cout << no_of_games(avg) << endl;
}
}
return 0;
}