View Code of Problem 8

#include <iostream>
using namespace std;

int main(){
    int n,day[13]={-1,31,28,31,30,31,30,31,31,30,31,30,31},l_num,prior,prev,sum;
    char num[10];
    scanf("%d",&n);
    getchar();
    
    while(n--){
        gets(num);
//        l_num = num[8]-'0';//字符转数字(注意中文)
        l_num = strlen(num) - 1;
        
        if(l_num == 0)
            prev = 9;
        else
            prev = l_num - 1;
        
        if(l_num == 9)
            prior = 0;
        else
            prior = l_num + 1;
        
        sum = 0;
        for(int j = 1;j <= 12;j ++){
            for(int k = 1;k <= day[j];k ++){
                if(k%10 == prev || k%10 == prior)
                    continue;
                else
                    sum ++;
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}

/*
Main.cc: In function 'int main()':
Main.cc:11:9: warning: 'char* gets(char*)' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
         gets(num);
         ^
Main.cc:11:17: warning: 'char* gets(char*)' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
         gets(num);
                 ^
Main.cc:13:27: error: 'strlen' was not declared in this scope
         l_num = strlen(num) - 1;
                           ^
*/

Double click to view unformatted code.


Back to problem 8