第一次上机报告

1.

#include <stdio.h>

int main()

{

    int a,b,c,d,e;

    scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);

    printf("Rank      Number\n----------------\nExcellent%7d\nGood%12d\nMedium%10d\nPass%12d\nFail%12d\n----------------\nTotal%11d\n",a,b,c,d,e,a+b+c+d+e);

    return 0;

}

这是更改后的代码 写的时候一开始先跳过了,后面着急一时没想到%nd,出了考场想到了。

4. #include <stdio.h>

int main()

{int y,m,c;

while(scanf("%d %d",&y,&m)!=EOF)

{

       if(y%4==0&&y%100!=0&&m==2)c=29;

    else if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)c=31;

 else c=30;

    printf("%d\n",c);

}

return 0;

}

这是考试时候的代码,漏看了闰年条件,一直一直找不到问题所在,没有重看题目。

更改后

#include <stdio.h>
int main()
{
    int y,m,d=28,c;
    while(scanf("%d %d",&y,&m)!=EOF)
    {
        if((y%4==0&&y%100!=0)||y%400==0)d=29;
        if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)c=31;
        else c=30;
        if(m==2)printf("%d\n",d);
        else printf("%d\n",c);
    }
    return 0;
}
} 其实这个代码还是有问题,于是我又修正了一次。问题所在可以请同学们细心的看看。

二次修正代码如下

#include <stdio.h>

int main()

{

    int y,m,c,d;

    while(scanf("%d %d",&y,&m)!=EOF)

    {

        if((y%4==0&&y%100!=0)||y%400==0)d=29;else d=28;

        if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)c=31;

        else c=30;

        if(m==2)printf("%d\n",d);

        else printf("%d\n",c);

    }

    return 0;

}

5. #include <stdio.h>

int main()

{ int unsigned a,u,c;

int tag;

scanf("%d %d %d",&a,&u,&c);

scanf("%d",&tag);

if(tag<0||tag>95)printf("Error");

 

return 0;

}

这是考试时的代码,怎么说呢,就是当时脑瓜子已经嗡嗡的了,没多想。

修正后

#include <stdio.h>

int main()

{

unsigned int ua,ub,uc;

int tag;

    scanf("%u%u%u",&ua,&ub,&uc);

    scanf("%d",&tag);

    if(tag<0||tag>95)printf("Error");

    else {

        if(tag>=64)

            ua|=1<<(tag-64);

        else if(tag>=32)

            ub|=1<<(tag-32);

        else uc|=1<<tag;   

        printf("ua=%u,ub=%u,uc=%u",ua,ub,uc);

    }

 

    return 0;

}

6.

#include <stdio.h>

int main()

{int n;

scanf("%d",&n);

for(int i=n;i>=1;i--)

{for(int h=i-1;h<n;h++)

printf(" ");    

for(int j=2*i-1;j>=1;j--)

       {

              printf("*");

       }

                     printf("\n");

                    

 

}

for(int a=1;a<n;a++)

{for(int h=n;h>a;h--)

printf(" ");    

for(int j=2*a+1;j>=1;j--)

       {

              printf("*");

       }

                     printf("\n");

                    

 

}

return 0;

}

这是考试时的代码,运行后的结果(右边)左边为修正后代码的运行结果。

第一次上机总结_#include

 

可以注意到每行都多了一个空格,考试的时候不知道怎么处理,越处理越乱。

晚上思考了一下改的代码如下

#include <stdio.h>

int main()

{

    int n;

    while(scanf("%d",&n)!=EOF){

   

    for(int i=1;i<=n;i++)

    {

        for(int j=i-1;j>0;j--)printf(" ");

        for(int h=2*n-(2*i-1);h>0;h--)printf("*");

        printf("\n");

    }

    for(int i=2;i<=n;i++)

    {

           for(int j=i+1;j<=n;j++)printf(" ");

           for(int h=2*i-1;h>0;h--)printf("*");

           printf("\n");

       }

    }

    return 0;

}

注意到 

不要把问题想的太复杂,大循环的第一个i尽量简单一点,往后写小循环的时候才不会互相绊脚。

心态爆炸的结果:

 

第一次上机总结_其他_02

 

 

 放平心态后,坐在自己自在的宿舍椅子上,悠闲地补题从九点五十到十点四十分左右就完成了。放轻松~相信自己,一步步入手就好了。

总结 考试时不要慌张,尽量把代码简单化,遇到问题可以先重看一下题目看看是否漏了条件。不要慌!不要慌!不要慌!

放平心态,晚上补题时的心态相比考试放松了很多,效率和改bug能力比考试时多了n倍,放平心态最重要。