新手入门 acm 输入输出练习

在线体验各类最新模型,更有模型 免费Token 额度领取!
立即体验
简介: A + B Problem(1000) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 355051    Accept...

A + B Problem(1000)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 355051    Accepted Submission(s): 110841

Problem Description
Calculate  A + B.
 
Input
Each line will contain two integers  A and  B. Process to end of file.
 
Output
For each case, output  A + B in one line.
 
Sample Input
1 1
 
Sample Output
2
 
 
题意:每一行输入包含两个整数a和b,每个案例输出a+b的值,在一行;
详见代码,
复制代码
#include<stdio.h>
int main()
{
    int a,b,sum;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
     sum
=a+b; printf("%d\n",sum); } return 0; }
复制代码

 

Sum Problem(1001)

Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 237995    Accepted Submission(s): 58229

Problem Description
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
 
Input
The input will consist of a series of integers n, one integer per line.
 
Output
For each case,  output SUM(n) in one line,  followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
 
Sample Input
1
100
 
Sample Output
1
 
5050
 
 
  题意:每行将输入一个整数n,对于每个案例,输出SUM(n) = 1 + 2 + 3 +  ... + n<求1到n的和> 在一行,紧随其后的是一个空行。
 
其他的就没什么可以注意的了。
详见代码:
复制代码
#include<stdio.h>
int main()
{
    int n,i,sum;

    while(scanf("%d",&n)!=EOF)
    {
            for(sum=0,i=0;i<=n;i++)
            sum=sum+i;
            printf("%d\n\n",sum);
    }
    return 0;
}
复制代码

 

 

A+B for Input-Output Practice (I)(1089)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 68193    Accepted Submission(s): 37929

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
 
题意:输入整数a和b,用空格分隔,每行一对整数。对于每一对输入整数a和b你应该输出他们的总和,输入a和b占在一行,输出占一行。
貌似和1000是一样的,o(∩_∩)o 哈哈!
复制代码
#include<stdio.h>
int main()
{
    int a,b,sum;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
     sum
=a+b;   printf("%d\n",sum); } return 0; }
复制代码

 

A+B for Input-Output Practice (II)(1090)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 51355    Accepted Submission(s): 33780

Problem Description
Your task is to Calculate a + b.
 
Input
Input contains an integer N in the first line, and then N lines follow. Each line consists of a pair 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
2
1 5
10 20
 
Sample Output
6
30
 
 
题意:输入包含一个整数N在第一行,然后有N数据。每一行包含一对整数a和b,用空格分隔,每行一对整数。
     对于每一对输入整数a和b你应该输出的总和,a和b在一行,输出输入各占一行。
比较1089,在1089的基础上多了一个控制输入测试的组数N,其他的一样。有木有。
详见代码;
复制代码
#include<stdio.h>
int main()
{
    int a,b,t,sum;
    scanf("%d",&t);   
    while(t--)
    {
        scanf("%d%d",&a,&b);
        sum=a+b;
        printf("%d\n",sum);
    }
    return 0;
}
复制代码

 

 

A+B for Input-Output Practice (III)(1091)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 60600    Accepted Submission(s): 31168

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
 
题意:输入包含多个测试用例。每个测试用例包含一对整数a和b,一对整数占一行。当输入测试用例为0 0时,终止输入和测试用例是不被处理。对于每一对输入整数a和b你应该输出他们的总和,a和b在一行,输出在一行。
 
比较1091,不一样的地方就是结束输入的条件不一样,其他的不变,有木有。
详见代码:
复制代码
#include<stdio.h>
int main()
{
    int a,b,sum;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
        if(a==0&&b==0)break;
        sum=a+b;
        printf("%d\n",sum);
        
    }
    return 0;
}
复制代码

 

 

 

A+B for Input-Output Practice (IV)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 53974    Accepted Submission(s): 28848

Problem Description
Your task is to Calculate the sum of some integers.
 
Input
Input contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.
 
Output
For each group of input integers you should output their sum in one line, and with one line of output for each line in input.
 
Sample Input
4 1 2 3 4
5 1 2 3 4 5
0
 
Sample Output
10
15
 
 
题意:输入包含多个测试用例。每个测试用例包含一个整数N,然后在同一行输入N个整数,。当测试用例是0时,终止输入和测试用例是不被处理。每组输出整数之和占一行,即,一行输入一行输出。
 
比较前面几题,这题稍微有点区别但变幻不大,N用来控制整数的个数。然后最后以0结束测试,
 
详见代码:
复制代码
#include<stdio.h>
int main()
{
    int a[100],t,i,sum;
    while(scanf("%d",&t)!=EOF)
    {
        if(t==0)
            break;
        sum=0;
        for(i=1;i<=t;i++)
        {
            scanf("%d",&a[i]);        
            sum=sum+a[i];
        }
        printf("%d\n",sum);
    }
    return 0;
}
复制代码

 

 

A+B for Input-Output Practice (V)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 39483    Accepted Submission(s): 26698

Problem Description
Your task is to calculate the sum of some integers.
 
Input
Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.
 
Output
For each group of input integers you should output their sum in one line, and with one line of output for each line in input.
 
Sample Input
2
4 1 2 3 4
5 1 2 3 4 5
 
Sample Output
10
15
 
 
题意:输入包含一个整数N在第一行,然后有N行测试用例,每一行都始于一个整数M,然后有M整数在同一个行。
每组输出整数之和且输出占一行,一行输入一行输出。
 
反思:是不是前两题的集合体哈,再仔细看看就知道了。有木有!
 
详见代码:
复制代码
#include<stdio.h>
int main()
{
    int a[100],t,i,p,sum;
    scanf("%d",&p);
    while(p--)
    {
        scanf("%d",&t);
        if(t==0)
            break;
        sum=0;
        for(i=1;i<=t;i++)
        {
            scanf("%d",&a[i]);
            sum=sum+a[i];
        }
        printf("%d\n",sum);
    }
    return 0;
}
复制代码

 

 

A+B for Input-Output Practice (VI)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 37174    Accepted Submission(s): 25051

Problem Description
Your task is to calculate the sum of some integers.
 
Input
Input contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.
 
Output
For each test case you should output the sum of N integers in one line, and with one line of output for each line in input.
 
Sample Input
4 1 2 3 4
5 1 2 3 4 5
 
Sample Output
10
15
 
 
 
这题就不要在啰嗦的在写题意了吧,貌似和上面的题目太像了,,,,o(∩_∩)o 哈哈
详见代码:
复制代码
#include<stdio.h>
int main()
{
    int a[100],t,i,sum;
    while(scanf("%d",&t)!=EOF)
    {
        sum=0;
        for(i=1;i<=t;i++)
        {
            scanf("%d",&a[i]);
            sum=sum+a[i];
        }
      printf("%d\n",sum);
    }
    return 0;
}
复制代码


看到这里我只想说,大家做题时候,代码写的格式一定要规范,最好就是形式统一,该空的时候就空格,不然代码都一个水平面就美观了,而且以后比赛的时候你还有2个队友,让他们给你检查错误的话,你的代码又不整洁,那么效率肯定不会高的,而且会有厌烦的心态,那就更好了,所以大家以后写代码尽量规范一点。就是这样了!

 

 

 

 

A+B for Input-Output Practice (VII)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 36617    Accepted Submission(s): 24438

Problem Description
Your task is to Calculate a + b.
 
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, and followed by a blank line.
 
Sample Input
1 5
10 20
 
Sample Output
6
 
30
 
 
题意:输入2个整数a和b,用空格分隔,每行一对整数。对于每一对输入整数a和b你应该输出他们的总和,a和b,身后跟着一个空行。
 
是不是又忘记空行了,输出的时候,这次又是中间再空一行哦,所以做题的时候一定要先看清楚题目的具体要求在动手编程,不然只会白白丢分!
 
详见代码:
复制代码
#include<stdio.h>
int main()
{
    int a,b,sum;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
        sum=a+b;
        printf("%d\n\n",sum);
    }
    return 0;
}
复制代码

 

 

 


终于快结束了,,,,,,搞得好辛苦,大家一定要认真对待啊!

 

 

 

 

A+B for Input-Output Practice (VIII)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 78908    Accepted Submission(s): 24263

Problem Description

 

Your task is to calculate the sum of some integers.

 

 

 

Input
Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.

 

Output
For each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.
 
Sample Input
3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3
 
Sample Output

10

 
15
 
6
 
 
题意:输入包含一个整数N在第一行,然后有N行测试数据。每一行都开始都有一个整数M,然后后面有M个整数在同一行。
每组输出整数之和,输出占一行,你必须注意,输出,每行之间有一个空行。
 
我只能说这题就是上面几道题目的大集合吧,所以是不是很简单呢。哈哈,所以对于acm的输入输出是不是有所了解了呢,
  对!就是那么简单!so easy!    o(∩_∩)o    那么,,,
 
 
是先看代码吧,
复制代码
#include<stdio.h>
int main()
{
    int a[100],t,i,p,sum;
    scanf("%d",&p);
    while(p--)
    {
        scanf("%d",&t);
        sum=0;
        for(i=1;i<=t;i++)
        {
            scanf("%d",&a[i]);        
            sum=sum+a[i];
        }
        printf("%d\n",sum);
        if(p)//中间空行用
            printf("\n");
    }
    return 0;
}
复制代码

 

 


到现在为止,你已经学会acm的简单输入输出了,(当然不是所有的输入输出,这个留给以后慢慢学习好了,)那么现在你已经可以在杭电上A题了,(为自己鼓掌,哈哈),接下来大家可以从简单题下手,本人建议可以先做11页的题。

当然不会的题欢迎到群内讨论,QQ群:  <主要面向刚刚入门的13级新生!>

最后还有一个小小的建议:学习贵在坚持!刚刚开始都是比较难的,所以大家要相互鼓励相互监督,共同进步!

          谢谢你的浏览!o(∩_∩)o

 
转载请注明出处:http://www.cnblogs.com/yuyixingkong/ 自己命运的掌控着!
目录
相关文章
|
存储 API
一种新的方法来存储用户信息——ThreadLocal
一种新的方法来存储用户信息——ThreadLocal
1963 0
|
7月前
|
人工智能 NoSQL 前端开发
Chap03. SpringAI
SpringAI整合多款主流大模型,支持对话、函数调用与RAG等架构,提供统一API简化开发。通过ChatClient封装交互,结合Prompt工程、工具调用与知识检索,可快速构建智能客服、哄哄模拟器、ChatPDF等应用,并支持多模态与持久化扩展,助力AI应用高效落地。
|
SQL 监控 关系型数据库
MySQL慢查询攻略
本文详细介绍了MySQL慢查询优化的全流程,从定位性能瓶颈到具体优化策略,再到高级调优与预防监控。首先通过开启慢查询日志和分析工具(如pt-query-digest)找到问题SQL,接着从索引优化(如最左前缀原则、覆盖索引)、SQL语句重构(如避免全表扫描)及EXPLAIN执行计划解析等方面进行核心优化。随后深入参数调优和架构升级,如调整innodb_buffer_pool_size、实施分库分表等。最后,通过实时监控工具(如PMM、Prometheus+Grafana)建立长效机制,并以电商订单查询为例,展示优化前后性能大幅提升的实战效果。
1147 0
|
机器学习/深度学习 算法 数据可视化
【从零开始学习深度学习】46. 目标检测中锚框的概念、计算方法、样本锚框标注方式及如何选取预测边界框
【从零开始学习深度学习】46. 目标检测中锚框的概念、计算方法、样本锚框标注方式及如何选取预测边界框
|
XML 设计模式 Java
这6种 Spring 依赖注入方式,你都会吗?
这6种 Spring 依赖注入方式,你都会吗?
2470 1
这6种 Spring 依赖注入方式,你都会吗?
|
缓存 监控 前端开发
java简历2年经验编写教程+面试题
是花了我很多天的心思,用心打造出来的Java简历分析模板,适合新手包装成有一点工作年限(1-2年),但又不会太老手的简历;让你的简历做得跟别人不一样;
5140 0
|
存储 Java 程序员
Java面试加分点!一文读懂HashMap底层实现与扩容机制
本文详细解析了Java中经典的HashMap数据结构,包括其底层实现、扩容机制、put和查找过程、哈希函数以及JDK 1.7与1.8的差异。通过数组、链表和红黑树的组合,HashMap实现了高效的键值对存储与检索。文章还介绍了HashMap在不同版本中的优化,帮助读者更好地理解和应用这一重要工具。
1292 5
|
存储 算法 索引
【查找算法】6种常见的查找算法简述及Python代码实现
【查找算法】6种常见的查找算法简述及Python代码实现
|
Java 开发者 Spring
Spring bean的生命周期详解!
本文详细解析Spring Bean的生命周期及其核心概念,并深入源码分析。Spring Bean是Spring框架的核心,由容器管理其生命周期。从实例化到销毁,共经历十个阶段,包括属性赋值、接口回调、初始化及销毁等。通过剖析`BeanFactory`、`ApplicationContext`等关键接口与类,帮助你深入了解Spring Bean的管理机制。希望本文能助你更好地掌握Spring Bean生命周期。
1530 1
|
Ubuntu Linux 开发者