7 8 9
Sample Output
1 4 7 2 5 8 3 6 9
HINT
二维数组存储矩阵。 #include
int i,j,c,d,m,n;
int a[100][100],b[100][100]; scanf(\ for(d=0;d {scanf(\ for(i=0;i scanf(\ for(i=0;i printf(\ else printf (\ printf(\ } printf(\} } Problem A: 编写函数maxValue(编程题) Description 编写一个函数maxValue,求三个整数的最大值,其原型为: int maxValue(int a,int b,int c); 其中a、b、c是参与比较的三个整数,返回值是三个数的最大值。 Input 输入三个int类型的整数,两两之间用空格隔开。 Output 输出三个整数的最大值。 Sample Input 1 2 3 Sample Output 3 HINT Append Code append.c, #include int maxValue(int a,int b,int c) { int x; x=a>b?a:b; if(x int main() { int x,y,z; scanf(\ printf(\ return 0; } Problem B: 编写函数myFloor和myCeil(编程题) 取整函数有四个,分别是 fix, floor, ceil, round。这里要求你编写myFloor和myCeil函数,它们的原型分别是: int myFloor(double data); int myCeil(double data); 其中myFloor函数的结果是不大于data的最大整数,myCeil函数的结果是不小于data的最小整数。 注意:不能使用math.h和stdlib.h两个头文件。 Input 输入有多行,每行是一个需要转换的实数。 Output 输出为多行,与上述输入一一对应。每行先输出floor函数的结果,再输出ceil函数的结果。两者之间用一个空格隔开。取整之后的结果不超出int类型的表示范围。 Sample Input 1.3 -1.5 2 Sample Output 1 2 -2 -1 2 2 HINT Append Code append.c, #include int myFloor(double data) { int i; if(data>0) for(i=0;;i++) {if(data-i>=0&&data-i<1) break; } else for(i=0;;i--) {if(i-data<=0&&i-data>-1) break; } return i; } int myCeil(double data) { int i; if(data>0) for(i=0;;i++) {if(i-data>=0&&i-data<1) break; } else for(i=0;;i--) {if(data-i<=0&&data-i>-1) break; } return i; } int main() { double data; while (scanf(\ { printf(\ } return 0; } Problem C: 求字符串的长度(编程题) Description 编写一个求字符串长度的函数,其原型如下: int strlen(char str[]); 其中str[]表示待求长度的字符串,返回值是str[]的长度。 注意:主函数已经给出,只需提交strlen()函数及必要的头文件包含命令。 Input 输入为多行。第一行N>0表示有N个测试用例,后面有N行,每行包含一个字符串(不超过1000个字符)。 Output 输出为多行,每行对应于一个测试用例。每行的格式为: case i:lenght=j. 其中i表示测试用例编号(从1开始),j表示相应的字符串长度。, #include int i; for(i=0;str[i]!='\\0';i++); return i; } int main() { int i,N; char str[1001]; scanf(\ getchar(); gets(str); printf(\ for (i=2;i<=N;i++) { gets(str); printf(\ } return 0; } Problem B: 你交换了吗?之二(函数) Description 从标准输入读取两个整数,按先小后大的次序输出,并且输出是否交换过位置。 注意:a和b相等时不产生交换。 请注意阅读append.c里的代码! Input 两个较小的整数a,b,用空格分开。 Output 输出有两种情况: 1) “a b NO”, 当a,b没有交换过 2) “b a YES”, 当a,b交换过 Sample Input 5 3 Sample Output 3 5 YES #include int is_swapped(int *p1,int *p2) { if(*p1>*p2) return 1; else return 0; } int main() { int a, b; scanf(\ if(is_swapped(&a, &b)) printf(\ else printf(\} Problem C: 编写函数unionSet(编程题) Description 编写一个函数unionSet,对2个集合求并集。其原型为: int unionSet(int setA[],int setB[],int numA,int numB); 其中setA和setB是两个待合并的集合,numA和numB分别是2个集合的元素个数。该函数将两个集合合并后,放在数组setA中,返回值为并集中的元素个数。 Input 输入为2行,每行是一个集合,每行的输入以数值0作为结束,个数不超过100个。2个集合合并后的元素取值均在[1,100]内。 Output 输出2个集合求并后的结果,两两之间用一个空格隔开。输出时,先输出第一个集合中的元素,再输出从第2个集合中合并过来的元素。见样例。 Sample Input 1 2 3 4 5 7 0 2 4 6 8 19 0 Sample Output 1 2 3 4 5 7 6 8 19 HINT Append Code append.c, #include int unionSet(int setA[],int setB[],int numA,int numB) { int i,j,k,m=0; for(i=0;setB[i]!=0;i++) {k=0; for(j=0;j if(setA[j]!=setB[i]) k++; } if(k==numA) { m++; setA[numA+m-1]=setB[i]; } } return numA+m; } int main() { int setA[101],setB[101],numA,numB,i; numA=numB=0; scanf(\ while (setA[numA]!=0) { numA++; scanf(\ } scanf(\ while (setB[numB]!=0) { numB++; scanf(\ } numA=unionSet(setA,setB,numA,numB); printf(\ for (i=1; i