导航:首页 > 数据处理 > 如何输入多组数据

如何输入多组数据

发布时间:2022-02-07 12:17:18

⑴ 怎么实现多组数据的同时输入和输出

定义一个数组变量用来读入,例如a[]
i=0;
a[0]=0;
while(a<>-1)do begin
i=i+1;
read(a[i]);
end;
如此输入数据,输出也是,用一个数组来存放输出数据并依次按格式输出

⑵ C++怎么输入多组数据

C++中实现多组数据输入主要有两种方式:

1.首先输入一个n,表示将有n个输入输出,例如:

#include<iostream>
usingnamespacestd;
intmain()
{
intn,a;
cin>>n;
while(n--){
cin>>a;
cout<<"输出:"<<a<<endl;
}
return0;
}
/*
运行结果:
3
111
输出:111
222
输出:222
333
输出:333
*/

2.使用while(cin>>a){}语句,直达输入ctrl+z,结束输入,例如:

#include<iostream>
#include<stdio.h>
usingnamespacestd;
intmain()
{
inta;
while(cin>>a){
cout<<"输出:"<<a<<endl;
}
return0;
}
/*
运行结果:
5
输出:5
6
输出:6
8
输出:8
^Z
*/

⑶ matlab 怎么输入多组数据

n=input('输入数字个数');
for ii=1:n
x(ii)=input('输入数字:');
end
mean(x)

⑷ C语言如何实现输入多组数据测试

循环按照格式读入每组数据即可。

对于输入多组数据测试的情况,需要约定结束的类型,常用的有两种:

1 当读入数据为一组特定值时,结束测试。

比如每组2个整型数据,以空格分隔,当输入的两个数均为-1时,结束测试。代码可以写作:

inta,b;
while(1)
{
scanf("%d%d",&a,&b);
if(a==-1&&b==-1)break;//退出测试的条件。
//测试代码。
}

2 当读到EOF时,结束测试。

同样读入两个整型数据,以空格分隔,当读到EOF时结束测试。代码可以写作:

inta,b;
while(scanf("%d%d",&a,&b)!=EOF)//当出现EOF时,结束测试。
{
//测试代码。
}

⑸ 怎么实现多组数据输入。格式要求如图

其实OnlineJudge上的多组数据输入和我们平时要求的多组数据输入是一样的
就是处理好第一组数据之后能再处理下一组输入
而不是将数据一次性全部输入
如果有case的数量就用它来计数,主要处理操作用放在循环里
如果没有的话就用scanf()的返回值
如:while(scanf("%d%d",&a,&b)==2)
{
...
}

⑹ ACM里说多组数据怎么输入啊

int n,sum=0;
while(scanf("%d",&n)!=EOF)
{
sum+=n;
}
EOF 处理到文件的结束就可以了。
根据题目的要求在合适的位置输出就可以了,如果每组数据都要输出,则写在循环里面,如果所有数据加完了在输出,那么就在循环外边。
只要你知道是要处理到文件结束就根据题目的要求做就可以了。
如果sum是求所有的输入的和,就是放在外边的!请楼上的兄弟认真思考后再发言。

⑺ 想问一下怎么输入多组数据啊,就是需要输入多组二维数组

inta[5][5];
inti,j,N;

scanf("%d",&N);
while(N--)
{
for(i=0;i<5;i++)
for(j=0;j<5;j++)
scanf("%d",&a[i][j]);
//以上就完成了数组的读入
//自己补充,查找最大数和四个最小数吧
//以下完成输出
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
printf("%d",a[i][j]);
printf(" ");
}
printf(" ");
}

⑻ C语言中如何实现多组数据输入输出

仔细认真看看下面的会对你有帮助的,嘿嘿

输入格式:有多个case输入,直到文件结束
输出格式:一行一个结果
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

Author
lcy

Recommend
JGShining

#include <stdio.h>

int main()
{
int a,b;
while( scanf( "%d%d" , &a , &b ) != EOF ) //输入直到文件结尾
{
printf( "%d\n" , a+b ); //一行一个结果
}
return 0;
}

HDOJ1090
输入格式:先输入有case数,再依次输入每个case
输出格式:一行一个结果
#include <stdio.h>
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

Author
lcy

Recommend
JGShining

int main()
{ int n,a,b;
scanf( "%d" , &n ); //输入的case数
while( n-- ) //控制输入
{ scanf( "%d%d" , &a , &b );
printf( "%d\n" , a+b ); //一行一个结果
}
return 0;
}

HDOJ1091
输入格式:每行输入一组case,当case中的数据满足某种情况时退出
输出格式:一行一个结果
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

Author
lcy

Recommend
JGShining

#include <stdio.h>

int main()
{
int a,b;
while( scanf( "%d%d" , &a , &b ) && (a||b) ) //输入直到满足a和b均为0结束
{
printf( "%d\n" , a+b ); //一行一个结果
}
return 0;
}

HDOJ1092
输入格式:每组case前有一个控制输入个数的数,当这个数为0结束
输出格式:一行一个结果
#include <stdio.h>
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

Author
lcy

Recommend
JGShining

int main()
{
int n,sum;
while( scanf( "%d" , &n ) && n ) //每组case前有一个控制该组输入数据的数,为0结束
{
int x;
sum = 0;
while( n-- ) //控制该组输入个数
{
scanf( "%d" , &x );
sum += x;
}
printf( "%d\n" , sum ); //一行一个结果
}
return 0;
}

HDOJ1093
输入格式:一开始有一个控制总的输入case的数,而每个case中又有一个控制该组输入数据的数
输出格式:一行一个结果
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

Author
lcy
5
#include <stdio.h>
int main()
{
int casnum,n,sum;
scanf( "%d" , &casnum ); //控制总的输入case的数
while( casnum-- ) //控制总的输入个数
{
int x;
sum = 0;
scanf( "%d" , &n ); //每个case中控制该组输入个数
while( n-- )
{
scanf( "%d" , &x );
sum += x;
}
printf( "%d\n" , sum ); //一行一个结果
}
return 0;
}

HDOJ1094
输入格式:总的case是输到文件结尾,每个case中的一开始要输入一个控制该组个数的数
输出格式:一行一个结果
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

6

#include <stdio.h>
int main()
{
int n,sum;
while( scanf( "%d" , &n ) != EOF ) //输出到文件结尾
{
int x;
sum = 0;
while( n-- ) //控制该组输入个数
{
scanf( "%d" , &x );
sum += x;
}
printf( "%d\n" , sum ); //一行一个结果
}
return 0;
}

HDOJ1095
输入格式:输入直到文件结束
输出格式:一行一个结果,结果输完后还有一个blank line
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
7
#include <stdio.h>
int main()
{
int a,b;
while( scanf( "%d%d" , &a , &b ) != EOF ) //输入直到文件结束
{
printf( "%d\n\n" , a+b ); //一行一个结果,结果输完后还有一个回车
}
return 0;
}

HDOJ1096
输入格式:一开始输入总的case数,每组case一开始有控制该组输入个数的数
输出格式:一行一个结果,两个结果之间有一个回车,注意最后一个case的处理。
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

#include <stdio.h>

int main()
{
int casnum,n,sum;
scanf( "%d" , &casnum ); //总的输入case数

while( casnum-- ) //控制输入组数
{
int x;
sum = 0;
scanf( "%d" , &n ); //控制每组的输入个数
while( n-- )
{
scanf( "%d" , &x );
sum += x;
}
printf( "%d\n" , sum ); //一行一个结果
if( casnum ) printf( "\n" ); //两两结果之间有一个回车,最后一个结果后面没有
}
return 0;
}

⑼ c语言如何实现输入数据有多组

#include <stdio.h>
void main()
{
int a,b,n;
scanf("%d",&n);
while(n<1||n>10)
{
printf("Error!!");
scanf("%d",&n);
}
while (n--)
{
scanf("%d%d",&a,&b);
printf("%d\n",a+b);
}
}

//*************************************************

#include <stdio.h>
void main()
{
int a,b;
while (scanf("%d%d",&a,&b)!=EOF)//以0结束就把0替换EOF
{
printf("%d\n",a+b);
}
}

⑽ c语言如何输入多组数据

#include<stdio.h>
intmain()
{
intn;
scanf("%d",&n);
while(n!=0)//等于0就退出,不等于0就继续输入
{
scanf("%d",&n);
printf("%d ",n);
}
}

阅读全文

与如何输入多组数据相关的资料

热点内容
如何开一个水产批发市场 浏览:910
子宫息肉怎么吃完美产品调理 浏览:382
桂林银行拒绝该交易多久解除 浏览:813
屏蔽群发信息怎么解除 浏览:465
广告代理费用怎么算 浏览:423
计算机子程序是什么 浏览:856
船务代理有什么意义 浏览:200
如何跳槽美国程序员 浏览:978
百老泉怎么做区域代理 浏览:6
信宜人民政府网招录信息栏在哪里 浏览:322
如何开通小程序接收验证码 浏览:660
平台买的信息属于什么费用 浏览:793
如何使用微信查看朋友的信息 浏览:839
如何看待现在理财产品违约 浏览:962
做酸奶代理商怎么样 浏览:455
python怎么爬取数据 浏览:583
网游充值怎么代理 浏览:464
如何看懂电商运营数据 浏览:116
聚熵信息技术怎么样 浏览:746
碳交易属于什么专业 浏览:914