ACM_编程与调试重点记录(十六)

1. putsprintf

#include "stdio.h"

int main(void)

{

    puts(10 > 8 ? "OK" : "Sorry");

}

运行结果:

OK

请按任意键继续. . .[微软用户1] 

#include "stdio.h"

int main(void)

{

    printf(10 > 8 ? "OK" : "Sorry");

}

运行结果:

OK请按任意键继续. . .

2. #include <math.h>

#include <stdio.h>

int main(void)

{

    int n;

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

        printf("%.0f[微软用户2] /n", 3 * pow(2, n - 1) - 2);

}

3.

#include"stdio.h"

#include"stdlib.h"

typedef struct node

{

    int data;

    struct node *next;

}linklist;

int main()

{

    linklist *head,*p,*tail;

    int x;

    head=tail=NULL;

    scanf("%d",&x);

    while (x!=0)

    {

        p=(linklist *)malloc(sizeof(linklist));

        p->data=x;

        p->next=NULL;

        if (head==NULL) head=tail=p;

        else

        {

            tail->next=p;

            tail=p;

        }

        scanf("%d",&x);

       // return(head);

    }

    while(x!=0)

    {

           printf("%d",head->data);

           head=head->next;

       }

}

没有输出结果,为什么呢???

4.HDOJ-NO.2000错在哪里?

#include"stdio.h"

#include"algorithm"

int main()

{

       char a,b,c,t;

       while(scanf("%c%c%c",&a,&b,&c)!=EOF)

       {

              if(a>b) swap(a,b);

              if(b>c) swap(b,c);

              if(a>b) swap(a,b);

              printf("%c%c%c%c%c/n",a,' ',b,' ',c);

       }

}

运行结果:

qwe

e q w

asd

 

 a s

zxc

 

 d z

 

 c x

预期结果:

qwe

e q w

asd

a d s

zxc

c x z

5. HDOJ-NO.2001

2001#include"stdio.h"

#include"math.h"

int main()

{

       double x1,y1,x2,y2;

       while(scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2)!=EOF)

              printf("%.2f/n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));

}

 

6. HDOJ-NO.2002

#include"stdio.h"

#define PI 3.1415926

int main()

{

       double r;

       while(scanf("%lf",&r)!=EOF)

              printf("%.3f/n",4.0/3.0*PI*r*r*r);

}

7. HDOJ-NO.2003

#include"stdio.h"

#include"math.h"

int main()

{

       double x;

       while(scanf("%lf",&x)!=EOF)

              printf("%.2f/n",fabs(x));

}

8. HDOJ-NO.2004

#include"stdio.h"

main()

{

    double score;

    while (scanf("%lf",&score)!=EOF)

    {

        if (score>100||score<0) printf("Score is error!/n");

        else

        {

            switch ((int)(score/10))

            {

            case 10:

            case 9:

                printf("A/n");

                break;

            case 8:

                printf("B/n");

                break;

            case 7:

                printf("C/n");

                break;

            case 6:

                printf("D/n");

                break;

            default:

                printf("E/n");

                break;

            }

        }

    }

}

9. HDOJ-NO.2005

#include <stdio.h>

/* 计算某个日期对应该年的第几天 */

int day_of_year(int year, int month, int day)

{

    int k, leap;

    int tab[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}

    };

    /* 判断year是否为闰年,当year是闰年时,leap=1;当year是非闰年时,leap=0 */

    leap = (year % 4 == 0 && year%100!=0 || year%400==0);

    /* 计算天数 */

    for (k = 1; k < month; k++)

        day = day + tab[leap][k];

    return day;

}

int main(void)

{

    int year, month, day;

    while (scanf("%d/%d/%d", &year,&month, &day)!=EOF)

        printf("%d/n", day_of_year(year, month, day));

}

10. HDOJ-NO.2006

#include <stdio.h>

int main()

{

       int x,n,total;

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

       {

              total=1;

              while(n--)

              {

                     scanf("%d",&x);

                     if(x%2==1) total*=x;

              }

              printf("%d/n",total);

       }

}

11. HDOJ-NO.2007

#include <stdio.h>

int main()

{

    int i,n,m,total1,total2;

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

    {

        total1=0;

        total2=0;

        for (i=m;i<=n;i++)

            if (i%2==0) total1+=(i*i);

            else total2+=(i*i*i);

        printf("%d %d/n",total1,total2);

    }

}

12. HDOJ-NO.2008

#include"stdio.h"

int main()

{

    double x;

    int n,total1,total2,total3;

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

    {

        total1=0;

        total2=0;

        total3=0;

        while (n--)

        {

            scanf("%lf[微软用户3] ",&x);

            if (x<0.0) total1++;

            else if (x>0.0) total3++;

            else total2++;

        }

        printf("%d %d %d/n",total1,total2,total3);

    }

}

13. HDOJ-NO.2009

#include"stdio.h"

#include"math.h"

int main()

{

    int m,i;

       double sum,n;

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

    {

        sum=0;

        for (i=1;i<=m;i++)

        {

            sum+=n;

            n=sqrt(n);

        }

        printf("%.2f/n",sum);

    }

}

 

 

 


 [微软用户1]这个换行了,而下面的没换行。

 [微软用户2]为什么此处非要用%.0f,用%d为何不行???#include <cmath>
         
         
double pow( double base, double exp );

 

 [微软用户3]格式控制说明与变量一定要一一对应,此处不可为%d

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值