Skip to content

Instantly share code, notes, and snippets.

@WindAzure
Last active August 26, 2018 05:08
Show Gist options
  • Save WindAzure/4a2820195e8e0fd778c6e68e62c7801c to your computer and use it in GitHub Desktop.
Save WindAzure/4a2820195e8e0fd778c6e68e62c7801c to your computer and use it in GitHub Desktop.
algorithm exercise
#include <stdio.h>
#define TABLE_LENGTH 3 * 5 + 1
int table[3][TABLE_LENGTH] = {
{ 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0 },
{ 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0 },
{ 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1 }
};
int main()
{
auto mod3Num = 0, mod5Num = 0, mod7Num = 0;
while (~scanf("%d%d%d", &mod3Num, &mod5Num, &mod7Num))
{
auto beginEntry = 0;
for (auto index = table[1][mod5Num]; index < TABLE_LENGTH; index += 5)
{
if (table[0][index] == mod3Num)
{
beginEntry = index;
break;
}
}
auto difference = (mod7Num - table[2][beginEntry] + 7) % 7;
auto result = beginEntry + difference * 15;
if (10 <= result && result <= 100)
{
printf("%d\n", result);
}
else
{
printf("No answer\n");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment