一、A+B for Input-Output Practice (I)

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

Your task is to Calculate a + b.

Too easy?! Of course! I specially designed the problem for acm beginners.

You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim

Input

The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.

Output

For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input

1 5
10 20

Sample Output

6
30

Hint

这是一个求两数之和的题目,输入多对用空格分开的两个数a b,输出a+b的和,每一对数据的和占一行。编写代码时需要注意的是,由于没有指出有多少对输入数据,因此我们可以编写如下代码:
 //C语言
#include < stdio.h > 
int main()   //把main函数定义成int类型

      int a,b;
      while(scanf("%d %d",&a, &b) != EOF)   // 输入结束时,scanf函数返回值为EOF,即没有数据输入时则退出while循环
            printf("%d\n",a+b);
      return 0; //返回值为0
}

//或者C++语言
#include < iostream >     //注意头文件的使用方法
using namespace std;
int main()
{
       int a,b;
       while(cin >> a >> b)
            cout << a+b << endl;
       return 0;
}

#include<stdio.h>
int main()
{
    int a,b;
    while(scanf("%d %d",&a,&b)!=EOF)
    printf("%d\n",a+b);
    return 0;
}

二、A+B for Input-Output Practice (III)

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

Your task is to Calculate a + b.

Input

Input contains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line. A test case containing 0 0 terminates the input and this test case is not to be processed.

Output

For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input

1 5
10 20
0 0

Sample Output

6
30

#include<stdio.h>
int main()
{
    int a,b;
    while(scanf("%d %d",&a,&b)!=EOF&&a!=0&&b!=0)
    printf("%d\n",a+b);
    return 0;
}

三、小金问呀问不会问题

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

众所周知,C语言的学习是我们程序设计基础的重点和主要内容。
小金在班里是一个爱学习的好孩子,但是他的编程能力却有点差,不过他坚信自己一定可以进步并追上其他同学。

Input

多组输入。
从键盘读入一个整数n,如果n >= 0代表小金考试进步了,如果n < 0代表小金退步了。

Output

如果小明进步了输出”Yes”,反之输出”No”。输出不包括引号,输入输出各占一行,保证数据合法。

Sample Input

100
-100

Sample Output

Yes
No

#include<stdio.h>
int main()
{
    int a;
    while(scanf("%d",&a)!=EOF){
        if(a>=0)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}

四、优越数

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

给定3个数,如果有两个数大于他们的平均数则称这组数为优越数。(定义纯属虚构)

Input

输入第一行是一个整数: 表示测试数据的组数。
对于每组测试数据,仅一行3个整数。

Output

对于每组输入数据输出一行,判断它是否为一组优越数,如果是输出“Yes”(输出不包括引号),否则输出“No”。

Sample Input

2
1 2 3
1 4 4

Sample Output

No
Yes

#include<stdio.h>
int main()
{
    int n,a,b,c,x;
    double ave;
    scanf("%d",&n);
    while(n-->0)
    {
        scanf("%d%d%d",&a,&b,&c);
        x = 0;
        ave = (a+b+c)/3.0;
        if(a>ave)
        {
            x++;
        }
        if(b>ave)
        {
            x++;
        }
        if(c>ave)
        {
            x++;
        }
        if(x==2)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}

五、分段函数求值

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

有如下分段函数
F(x) = x^2 + 1   当x> 0时;
F(x) = -x   当x<0时;
F(x) = 100.0  当x=0时;
编程根据输入的不同x(x为实数),输出其对应的函数值

Input

多组输入,每组一个实数x。处理到文件结束。

Output

对于每组输入x,输出其对应的F(x),每组一行,结果保留1位小数。

Sample Input

8.00
-5.0

Sample Output

65.0
5.0

#include<stdio.h>
int main()
{
    double x;
    while(scanf("%lf",&x)!=EOF)
    {
        if(x>0)
            printf("%.1lf\n",x*x+1);
        else if(x==0)
            printf("100.0\n");
        else
            printf("%.1lf\n",-x);
    }
    return 0;
}

六、直角坐标系

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

X是一个喜欢数学的小孩,现在他刚刚学了坐标系。他想知道点(X,Y)在第几象限内。输入数据保证点不在坐标轴及原点上。

Input

多组输入。

每组输入两个整数X,Y,代表点(X,Y),中间用空格隔开。

Output

输出一个整数代表点在第几象限内。

Sample Input

2 3
-2 -3

Sample Output

1
3

#include<stdio.h>
int main()
{
    int a,b;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
        if(a>0&&b>0)
            printf("1\n");
        else if(a>0&&b<0)
            printf("4\n");
        else if(a<0&&b<0)
            printf("3\n");
        else if(a<0&&b>0)
            printf("2\n");
    }
    return 0;
}

七、计算球体积

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

根据输入的半径值,计算球的体积。

Input

输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。

Output

输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。

Sample Input

1
1.5

Sample Output

4.189
14.137

Hint

#define PI 3.1415927

#include<stdio.h>
#define PI 3.1415927
int main()
{
    double a;
    while(scanf("%lf",&a)!=EOF)
    {
        printf("%.3lf\n",4*PI*a*a*a/3);                        《换成4/3*PI*a*a*a就不对》
    }
    return 0;
}

八、洗衣服

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

X是一个勤劳的小孩,总是会帮助大人做家务。现在他想知道对于一根长为L的绳子能晾开多少件宽为W的衣服,显然这些衣服不能相互叠压。

Input

多组输入。

每组输入两个整数L,W。

Output

输出答案。

Sample Input

10 5
10 4

Sample Output

2
2

#include<stdio.h>
int main()
{
    int a,b;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
        printf("%d\n",a/b);
    }
    return 0;
}

九、压岁钱

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

SuShan过年要给孩子们发压岁钱喽,由于家里孩子很多,这可急坏了SuShan。你肯定以为她在担心钱不够,那你错了,她可是个有钱人儿,不差钱儿。她担心的是每个人分多少从而保证公平。
   SuShan从瑞士银行提出1000000来给孩子们分,由于来的孩子的数目不确定,所以SuShan希望你能帮他计算一下每个孩子给多少钱,从而保证每个孩子得到的都是整数。

Input

输入有多组数据,第一行 T 代表数据的组数。
接下来有 T 行,每行一个整数 N,代表孩子的数目,1<= N <= 10000000。

Output

只有一行。如果能够分给每个孩子相同数目的压岁钱,且都是整数,则输出每个孩子得到的钱数。否则输出No。

Sample Input

3
1
2
3

Sample Output

1000000
500000
No

#include<stdio.h>
int main()
{
    int T,a;
    scanf("%d",&T);
    while(T-->0)
    {
        scanf("%d",&a);
        if(1000000%a==0)
            printf("%d\n",1000000/a);
        else
            printf("No\n");
    }
    return 0;
}

十、明天是几号?

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

忙碌了一天的 bLue 累得瘫在床上,他想知道明天是几号,你能告诉他吗?

Input

输入数据有多组(数据组数不超过 50000),到 EOF 结束。

每组数据输入一行,包含用空格隔开的 3 个整数,表示今天的日期,分别为年、月、日。

保证输入日期的年份在 1900 到 2035 之间。

Output

对于每组数据,在一行中输出明天的日期,格式为 "y m d",分别表示年、月、日。

Sample Input

2016 12 27
2016 2 29

Sample Output

2016 12 28
2016 3 1

Hint

能被 4 整除且非整百年的,或能被 400 整除的为闰年。

#include<stdio.h>
int main()
{
    int a,b,c;
    while(scanf("%d%d%d",&a,&b,&c)!=EOF)
    {
        if(c<=27){
            printf("%d %d %d\n",a,b,c+1);
        }
        else if(c==28){
            if(b!=2){
                 printf("%d %d %d\n",a,b,c+1);
            }
            else
            {
                if((a%4==0&&a%100!=0)||a%400==0)
                    printf("%d %d %d\n",a,b,c+1);
                else
                    printf("%d 3 1\n",a);
            }
        }
        else if(c==29)
        {
            if(b!=2){
                 printf("%d %d %d\n",a,b,c+1);
            }
            else
            {
                    printf("%d 3 1\n",a);
            }
        }
        else if(c==30)
        {
            if(b==4||b==6||b==9||b==11)
            {
                 printf("%d %d 1\n",a,b+1);
            }
            else{
                 printf("%d %d %d\n",a,b,c+1);
            }
        }
        else if(c==31)
        {
            if(b!=12)
            {
                printf("%d %d 1\n",a,b+1);
            }
            else{
                printf("%d 1 1\n",a+1);
            }
        }
    }
    return 0;
}

C语言程序设计基础OJ练习题(实验三while循环结构)相关推荐

  1. C语言程序设计基础OJ练习题(实验十结构体与共用体)

    一.英文金曲大赛 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 我们在"渊 ...

  2. c程序设计语言第五单元,(C语言程序设计基础课件)第五单元循环结构程序设计.pptx...

    第五单元 循环结构程序设计;知识目标 了解goto语句以及用goto语句构成循环:掌握用while语句.do-while语句.for语句实现循环:熟悉循环语句的嵌套:掌握break语句和continu ...

  3. java语言读后感_《Java语言程序设计基础篇》读后感锦集

    <Java语言程序设计基础篇>是一本由梁著作,机械工业出版社出版的平装图书,本书定价:58.00元,页数:500,特精心从网络上整理的一些读者的读后感,希望对大家能有帮助. <Jav ...

  4. c语言编程星阵直角三角形,C语言星阵图形使用FOR,WHILE,DO-WHILE 三种循环结构实现.doc...

    * * * * * * * * * * * * * * * * * * * * * * * * * 以上星阵图形使用C语言FOR,WHILE,DO-WHILE 三种循环结构实现. [程序星阵1]for ...

  5. Python语言程序设计基础_实验四_函数(三)_答案_通识教育必修课程_上海师范大学

    实验4 函数(二) 答案 Python语言程序设计基础 上海师范大学 通识教育必修课程 授课教师:吴春英 徐晓钟 题目来源:上海师范大学网络教学平台(超星泛雅) I 实验要求

  6. 【C语言入门】SDUT《程序设计基础I 》实验1-顺序结构程序设计题解 c语言入门语法讲解

    SDUT<程序设计基础I >实验1-顺序结构程序设计题解 && c语言语法讲解 链接 前言: 为方便更多同学入门C语言, 特在此编写SDUT OJ c语言入门150题题解即 ...

  7. 周信东c语言实验二实验报告,周信东主编最新版C语言程序设计基础实验一实验报告.doc...

    周信东主编最新版C语言程序设计基础实验一实验报告.doc 下载提示(请认真阅读)1.请仔细阅读文档,确保文档完整性,对于不预览.不比对内容而直接下载带来的问题本站不予受理. 2.下载的文档,不会出现我 ...

  8. 《C语言程序设计基础》第2章作业,清华大学出版社-图书详情-《C语言程序设计基础实验与题解》...

    C语言是国内外广泛使用的一种程序设计语言,也是初学程序设计人员的首选入门程序设计语言.C语言具有表达能力强.代码质量高和可移植性好等特点,既具有高级语言的特点,又具有汇编语言的优点,越来越受到人们的欢 ...

  9. c++程序设计(第三版) pdf_【好课传送】C++语言程序设计基础入门视频

    [机器学习之美导读]C/C++语言发展至今已有40多年的历史,在全世界应用非常广泛,是主流的开发语言. C/C++体系语言是IT工程师长远发展的首选,具备C++背景的工程师被互联网IT后端团队认定为团 ...

最新文章

  1. Ansible — Playbooks
  2. [iOS]C语言技术视频-10-指针变量
  3. Hadoop文件系统常用命令
  4. MySQL性能优化之char、varchar、text的区别
  5. Stream流中的常用方法_skip
  6. 数据结构与算法-- 广度优先打印二叉树
  7. 用crontab命令实现每天定时的病毒扫描
  8. iPhone苹果手机iOS14更新升级到iOS15需要多久?
  9. 中华传统美德故事(五)
  10. 鼠标计算机英语怎么说,鼠标英语
  11. 概率算法中的Monte carlo算法
  12. PWmat案例赏析:计算精度高、速度快的第一性原理计算,研究表面终端结构对NV色心影响
  13. 程序员如何使正确卖出自己的程序但是不想被人知道代码的具体实现?
  14. 第十四届蓝桥杯校内模拟赛第二期-Java个人题解(仅供参考)
  15. MySQL——O4. 表结构设计和数据类型优化
  16. kb2919442不适用计算机,无法更新kb2919442,kb2919355,显示此更新不适用于你的计算机,求助...
  17. 【java基础】——一维数组和二维数组存储占用内存大小问题
  18. Android中文API文档
  19. 初识HTML之标记2(标题标记、段落标记、引用文本标记)
  20. openflow hands on tutorial 使用心得

热门文章

  1. 百度淘宝关键词排名系统【胖虎图图-互动点击专家】
  2. CTF 表情符号编码/解码
  3. 华升股份:参股湘财证券 洼地井喷
  4. golang对mongo数据库索引的创建,删除操作
  5. Kaggle:数据践行者的好去处(如何开展大数据的实践?)
  6. 虎牙爬虫爬取直播间热度尝试记录(xpath)
  7. DesignSpark Mechanical 3D设计软件
  8. Linux-权限管理应用实例(警察与土匪游戏)
  9. ps照片处理下雪效果
  10. 精美网页flash幻灯片代码