35、 一维数组的逆序(编程题)
Description
编程,实现对一个一维数组的逆序,即将数组的元素反转。 Input
输入分多行,第一行是N>0,表示有N个用例。
每个用例的输入有1行或2行,其中第一行是0<=M<=1000,表示该数组有M个整数。如果M>0,则第二行包含M个整数,两两之间用空格隔开;如果M=0,则该用例没有第二行输入。 Output
输出为N行,每行与上述输入一一对应,分别是对应用例的逆序。输出格式为: case i:d1 d2 ...
其中i表示用例编号(从1开始),d1、d2等是数组逆序后的结果,两两之间用空格隔开。如果该用例不包含任何输入,即:M=0,则仅输出: case i:
Sample Input 3 10
10 9 8 7 6 5 4 3 2 1 0 5
1 2 3 4 5
Sample Output
case 1:1 2 3 4 5 6 7 8 9 10 case 2:
case 3:5 4 3 2 1 Answer
#includeint main() { int N,M[10000],a[100][1001],i,j; scanf(\ for(i=0;i0;j--) printf(\ printf(\ printf(\ } else printf(\ } return 0; }
36、 结构体的使用(编程题)
Description
设有结构体定义如下: typedef struct Student {char major[50];//专业 char name[50];//姓名
int score[3];//3门课程的成绩 } STU;
编写一个子函数,输出每个学生的总分,函数原型如下: void printInfo(STU students[],int num);
其中students[]是由num个STU类型的结构体组成的数组。 输出格式见下。
注意:主函数已经给出,提交时需提交以下内容:上述结构体STU的定义(直接复制上就可以,要放在头文件包含命令之后)、必要的头文件包含命令以及printInfo函数的代码。 Input
输入为多行。第一行N>0表示有N个学生的信息。之后有N行,每一行包含5个部分,分别表示每位学生的专业、姓名和3门课程的成绩,两两之间用空格隔开。成绩为正整数。 Output
输出为N行,每一行为一名学生的信息,格式为: major,name:totalSocre.
其中major表示学生的专业,name表示学生的姓名,totalScore表示该生的总分。所有的标点符号均为半角字符。
Sample Input 3
Computer Tom 100 98 89 Information Jack 98 89 87 Management Mary 89 89 89 Sample Output Computer,Tom:287. Information,Jack:274. Management,Mary:267. Answer
#includetypedef struct Student {
char major[50]; char name[50]; int score[3]; } STU;
void printInfo(STU students[],int num) { int i;
for(i=0;iprintf(%udents[i].score[2]); printf(\} }
int main() {
int i,N;
scanf(\ STU stus[N]; getchar();
for (i=0;iscanf(\
scanf(\ }
printInfo(stus,N); return 0; }