几道水题(18岁的生日,空心三角形)

18岁的生日:

 

 1 #include<stdio.h>
 2 int m[13]={31,28,31,30,31,30,31,31,30,31,30,31};
 3 int nian(int x){
 4     if(x%400==0||(x%4==0&&x%100!=0))return 1;
 5     else return 0;
 6 }
 7 int find(int x,int y,int z){
 8     if(nian(x))m[1]=29;
 9     else m[1]=28;
10     int tot=0;
11     for(int i=0;i<y-1;i++)tot+=m[i];
12     return tot+z;
13 }
14 int main(){
15     int x,y,z,tot,T;
16     scanf("%d",&T);
17     while(T--){tot=0;scanf("%d-%d-%d",&x,&y,&z);
18         if(y==2&&z==29)puts("-1");
19         else{
20             for(int i=x+1;i<x+18;++i){
21                 if(nian(i))tot+=366;
22                 else tot+=365;
23             }
24             if(nian(x))tot+=366-find(x,y,z);
25             else tot+=365-find(x,y,z);
26             printf("%d\n",tot+find(x+18,y,z));
27         }
28     }
29     return 0;
30 }

空心三角形:

#include<stdio.h>
#include<string.h>
int main(){
    char c,m[100][100];int n,x,y,flot=0;
    while(scanf("%c %d",&c,&n),c!='@'){memset(m,0,sizeof(m));if(flot)puts("");flot++;
        getchar();
        for(y=0;y<n;++y)for(x=0;x<2*n;++x)m[y][x]=' ';
        for(y=0;y<n;++y){
            for(x=0;x<2*n;++x){
                m[y][n-1-y]=c;
                m[y][n-1+y]=c;
                if(y==n-1)m[y][x]=c;
                m[y][n+y]='\0';
            }
            printf("%s\n",m[y]);
        }
    }
    return 0;
}

 

posted @ 2015-07-24 17:51  handsomecui  阅读(210)  评论(0编辑  收藏  举报