-
Notifications
You must be signed in to change notification settings - Fork 34
/
10070.cpp
executable file
·121 lines (96 loc) · 2.42 KB
/
10070.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* Problem: Leap Year or Not Leap Year and..UVa 10070
Programmer: Md. Mahmud Ahsan
Compiled: Visual C++ 6.0
Date: 03-01-05
*/
#include <iostream>
#include <string>
using namespace std;
const long length = 10000;
char str[length]; // input
long len; // input length
bool leapYear, huluculu, buluculu;
// prototypes
void chkLeapYear();
void chkHuluculu();
void chkBuluculu();
//===================================================================
int main(){
bool newLine = false;
while (cin >> str){
len = strlen(str) - 1;
leapYear = huluculu = buluculu = false;
chkLeapYear(); chkHuluculu(); chkBuluculu();
if (newLine) cout << endl;
if (!leapYear && !huluculu && !buluculu){
cout << "This is an ordinary year." << endl;
continue;
}
if (leapYear)
cout << "This is leap year." << endl;
if (huluculu)
cout << "This is huluculu festival year." << endl;
if (buluculu)
cout << "This is bulukulu festival year." << endl;
if(!newLine) newLine = true;
}
return 0;
}
//===================================================================
void chkLeapYear(){
bool four = false, hundred = false, fourHundred = false;
int last, bfLast, lastTwo;
last = str[len] - 48;
bfLast = str[len-1] - 48;
lastTwo = last + (bfLast * 10);
if (lastTwo == 0){
four = true;
hundred = true;
}
else if (lastTwo % 4 == 0)
four = true;
if (lastTwo == 0){
last = str[len-2] - 48;
bfLast = str[len-3] - 48;
lastTwo = last + (bfLast * 10);
if ((lastTwo == 0) || (lastTwo % 4 == 0))
fourHundred = true;
}
if ((four && !hundred) || fourHundred)
leapYear = true;
}
void chkHuluculu(){
long sum = 0, last;
bool three = false, five = false;
for (int i = 0; str[i]; i++)
sum = sum + (str[i] - 48);
if (sum % 3 == 0)
three = true;
last = str[len] - 48;
if (last == 0 || last == 5)
five = true;
if (three && five)
huluculu = true;
}
void chkBuluculu(){
bool five = false, eleven = false;
long sum = str[0] - 48;
int last = str[len] - 48;
if (last == 0 || last == 5)
five = true;
bool plusMinus = false;
for (int i = 1; str[i]; i++){
if (plusMinus){
sum = sum + (str[i] - 48);
plusMinus = !plusMinus;
}
else{
sum = sum - (str[i] - 48);
plusMinus = !plusMinus;
}
}
if (sum % 11 == 0)
eleven = true;
if (five && eleven && leapYear)
buluculu = true;
}