Created
April 8, 2018 00:55
-
-
Save georgelima/f8fdaff78c71805000a2f3e3590ebcb6 to your computer and use it in GitHub Desktop.
URI 1279
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdio.h> | |
#include <string> | |
#include <cmath> | |
using namespace std; | |
// Helpers | |
int isDivisibleBy3(const string& str) { | |
int sum = 0; | |
for (size_t i = 0; i < str.size(); i++) { | |
sum += (str[i] - '0'); | |
} | |
return !(sum % 3); | |
}; | |
int isDivisibleBy5(const char c) { | |
return c == '5' || c == '0'; | |
}; | |
int isDivisibleBy11(const string& str) { | |
int len = str.size(); | |
int sum = 0; | |
for (int i = 0; i < len; i++) { | |
if (i & 1) { | |
sum -= str[i] - '0'; | |
} else { | |
sum += str[i] - '0'; | |
} | |
} | |
return !(abs(sum) % 11); | |
}; | |
// Leap year -> divisible by 4 and 100 | |
int isDivisibleBy4(const char last, const char pen) { | |
int sum = (10 * (pen - '0')) + (last - '0'); | |
return !(sum % 4) || sum == 0; | |
}; | |
int isDivisibleBy100(const string& str) { | |
int len = str.size(); | |
return str[len - 1] == '0' && str[len - 2] == '0'; | |
}; | |
int isDivisibleBy400(const string& str) { | |
int len = str.size(); | |
int num = ((str[len - 4] - '0') * 1000) + ((str[len - 3] - '0') * 100) + ((str[len - 2] - '0') * 10) + (str[len - 1] - '0'); | |
return !(num % 400); | |
}; | |
// Hucululu -> divisible by 15 | |
int isDivisibleBy15(const string& str) { | |
return isDivisibleBy3(str) && isDivisibleBy5(str[str.size() - 1]); | |
}; | |
// Bucululu -> divisible by 55 and leap | |
int isDivisibleBy55(const string& str) { | |
return isDivisibleBy5(str[str.size() - 1]) && isDivisibleBy11(str); | |
}; | |
int isLeapYear(const string& str) { | |
int len = str.size(); | |
return (isDivisibleBy4(str[len - 1], str[len - 2]) && !isDivisibleBy100(str)) || isDivisibleBy400(str); | |
}; | |
int isHucululuYear(const string& str) { | |
return isDivisibleBy15(str); | |
}; | |
int isBulukuluYear(const string& str) { | |
return isDivisibleBy55(str) && isLeapYear(str); | |
}; | |
int main() { | |
string str, ans = ""; | |
while(cin >> str) { | |
int isOrdinalYear = 1; | |
if (isLeapYear(str)) { | |
ans += "This is leap year.\n"; | |
isOrdinalYear = 0; | |
} | |
if (isHucululuYear(str)) { | |
ans += "This is huluculu festival year.\n"; | |
isOrdinalYear = 0; | |
} | |
if (isBulukuluYear(str)) { | |
ans += "This is bulukulu festival year.\n"; | |
isOrdinalYear = 0; | |
} | |
if (isOrdinalYear) { | |
ans += "This is an ordinary year.\n"; | |
} | |
ans += "\n"; | |
} | |
while(ans.back() == '\n') ans.pop_back(); | |
ans.push_back('\n'); | |
cout << ans; | |
return 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment