View Code of Problem 8

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define PR printf
#define SC scanf
#define D "%ld"
long days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int check(long mon, long num);
int main(){
	long t, i, j;
	long dec[512];
	long num;
	char s[64], c[4];
	SC(D, &t);
	for (i = 0; i < t; i++) {
		scanf("%s", s);
		strncpy(c, s + strlen(s) - 1, 1);
		num = atoi(c);
		dec[i] = 0;
		for (j = 0; j < 12; j++){
			dec[i] += check(j, num);
		}
	}
	for (i = 0; i < t; i++) {
		PR(D"\n", 365 - dec[i]);
	}
	return 0;
}

int check(long mon, long num) {
	long i, j;
	long tot = 0;
	for (i = 1; i <= days[mon]; i++) {
		if ((i % 10 + 1) % 10 == num || (i % 10 + 9) % 10 == num) {
			tot ++;
		}
	}
	return tot;
}

Double click to view unformatted code.


Back to problem 8