考研复试机试题(2010)
转载请标明出处:牟尼的专栏 http://blog.csdn.net/u012027907
解答:
/* * 描述: 机试题A解答 * 作者: 张亚超 * 博客: 牟尼的专栏 http://blog.csdn.net/u012027907 * 日期: 2014/7/21 */ #include "stdio.h" #define Max 1000 int getEveSum(int num){ //求各位的数字和 int sum = 0; while(num != 0){ int r = num%10; num = num/10; sum += r; } return sum; } void sort(int store[],int count){ //冒泡排序 for(int i = 0; i < count; i++) for(int j = i+1; j < count; j++){ if(store[i] > store[j]){ int temp = store[i]; store[i] = store[j]; store[j] = temp; } } } void print(int store[],int count){ //打印输出 for(int i = 0; i < count; i++) printf("%d ",store[i]); printf("\n"); } int main(){ int store[Max]; int count = 0; int num; scanf("%d",&num); while(num != 0){ store[count++] = getEveSum(num); scanf("%d",&num); } sort(store,count); print(store,count); return 0; }
解答:
/* * 描述: 机试题B解答 * 作者: 张亚超 * 博客: 牟尼的专栏 http://blog.csdn.net/u012027907 * 日期: 2014/7/21 */ #include <stdio.h> #define M 100 #define N 100 void MaAnPoint(int matrix[][N],int m, int n){ bool isExist = false; int min,jj,max,ii; for(int i = 0; i < m; i++){//一行一行遍历 min = matrix[i][0]; jj = 0; for(int d = 0; d < n; d++){ //找出每行的最小值及其下标 if(matrix[i][d] < min){ min = matrix[i][d]; jj = d; } } max = matrix[0][jj]; ii = 0; for(int a = 0; a < m; a++){//找出每列的最大值及其下标 if(matrix[a][jj] > max){ max = matrix[a][jj]; ii = a; } } if(max == min){ //相等,则为马鞍点 isExist = true; printf("%d %d %d\n",ii,jj,max); } } if(!isExist){ //不存在马鞍点 printf("no\n"); } } int main() { int matrix[M][N]; int m,n; scanf("%d%d",&m,&n); for(int i = 0; i < m; i++) for(int j = 0; j < n; j++){ scanf("%d",&matrix[i][j]); } MaAnPoint(matrix,m,n); return 0; }
转载请标明出处:牟尼的专栏 http://blog.csdn.net/u012027907
原文地址:http://blog.csdn.net/u012027907/article/details/38001403