1日期问题

题解如下:

#include<stdio.h>
#include<math.h>
int year [2][13]=
{
    {0,31,28,31,30,31,30,31,31,30,31,30,31},
    {0,31,29,31,30,31,30,31,31,30,31,30,31},
};
bool isLeap(int year)//判断是否是闰年 
{
    return ((year%4==0 && year%100!=0)||(year%400==0)) ;
}

int main()
{
    int t1,y1,m1,d1;
    int t2,y2,m2,d2;
    while(scanf("%d%d",&t1,&t2)!=EOF){

        if(t1>t2)
        {
            int n=t1;
            t1=t2;
            t2=n;
        }
        y1=t1/10000,m1=t1%10000/100, d1=t1%10;
        y2=t2/10000,m2=t2%10000/100, d2=t2%10;
        int ans=1;
        while(!(y1==y2&&m1==m2&&d1==d2))
        {
            d1++;
            ans++;
            if(d1==year[isLeap(y1)][m1]+1 ) //满当月天数 
            {
                m1++;
                d1=1;
            }
            if(m1>12)
            {
                y1++;
                m1=1;
            }

        }

        printf("%d",ans);


    }

    return 0;

} 

2. 进制问题

  • p进制数x转化为十进制y 
#include<stdio.h>
//p进制数x转化为十进制y 
int main()
{
    int p,x;
    scanf("%d%d",&p,&x);
    int y=0,product =1;
    while(x!=0){
        y=y+(x%10)*product;
        x=x/10;
        product*=p;
    }
    printf("%d",y);
    return 0;

} 
  • 10进制数y转化为Q进制z
#include<stdio.h>
//10进制数y转化为Q进制z
int main()
{
    int z[40],num=0;
    int y,q;
    scanf("%d%d",&y,&q);
    do{
        z[num++]=y%q;
        y=y/q;
    }while(y!=0);
    for(int i=num-1;i--;i>0)
    {
        printf("%d",z[i]);
    }

    return 0;

} 

3字符串问题

题解如下:

#include<stdio.h>
#include<math.h>
#include<cstring>
int main()
{

    char str[90][90];
    int i=0;

    while(scanf("%s",str[i])!=EOF)
    {
    i++;

    }

    for(i=i-1;i>=0;i--)
    {
        printf("%s",str[i]);
        if(i>0) printf(" ");
    }


    return 0;

} 
02-11 21:26