Submission
Status:
PPPPP-P-PP
Score: 80
User: okji15019
Problemset: เลขดวง
Language: cpp
Time: 0.001 second
Submitted On: 2024-10-16 22:41:13
#include <stdio.h>
#include <string.h>
#include <math.h>
int main() {
int mm, birthday, firstday, bdday, perm[4] = {1,1,1,1}, x = 1, enter = 0, nenter = 0, i;
scanf("%d", &mm);
scanf("%d", &firstday);
scanf("%d", &birthday);
int fd = firstday, fd2 = firstday;
bdday = (birthday%7) + firstday - 1;
if (bdday > 7) bdday -= 7;
if (bdday == 1) perm[0] = 0;
if (bdday == 7) perm[1] = 0;
if (birthday == 1) perm[0] = 0;
while (x <= mm) {
if (fd>7) {
fd = 1;
enter++;
}
x++;
}
x = 0;
for (i=0;i<=mm;i++) {
if (fd2>7) {
fd2 = 1;
nenter++;
x++;
}
if (enter == 1) {
if (bdday < x) {
perm[2] = 0;
}
}
}
int lastday = (firstday + mm - 1) % 7;
if (lastday == 0) lastday = 7;
if (birthday > mm - lastday) perm[3] = 0;
//printf("%d\n", lastday);
if (birthday == mm) perm[1] = 0;
if (birthday < 8 - firstday) perm [2] = 0;
int sum=0;
if (perm[0] == 1) sum += birthday - 1;
if (perm[1] == 1) sum += birthday + 1;
if (perm[2] == 1) sum += birthday - 7;
if (perm[3] == 1) sum += birthday + 7;
//printf("%d %d %d %d\n", perm[0], perm[1], perm[2], perm[3]);
printf("%d", sum);
return 0;
}