考研复试机试题(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; }
解答:
/* * 描述: 机试题C解答 * 作者: 张亚超 * 博客: 牟尼的专栏 http://blog.csdn.net/u012027907 * 日期: 2014/7/21 */ #include<stdio.h> #include<string.h> #define Max 50 bool isDigit(char ch){ //判断是否是数字 if(ch >= '0' && ch <= '9') return true; else return false; } int main(){ char str[Max]; scanf("%s",str); putchar(str[0]); //输出第一个字符 char prior = str[0]; //前一个字符 char ch; //当前字符 char next; //下一个字符 int i = 1; int num = 0; while(str[i] != '\0'){ ch = str[i]; if(isDigit(ch)){ //判断是否是数字 num = num*10 + ch - '0'; //累加数字 if(str[i+1] != '\0') next = str[i+1]; if(isDigit(next)){ //下一个字符还是数字,则继续 i++; continue; }else{ // 输出压缩的字符 for(int j = 1; j < num; j++) putchar(prior); num = 0; } }else{ putchar(ch); } prior = ch; i++; } printf("\n"); return 0; }
转载请标明出处:牟尼的专栏 http://blog.csdn.net/u012027907