zoukankan      html  css  js  c++  java
  • 考研复试机试题(2010)

    考研复试机试题(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("
    ");
    }
    
    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
    ",ii,jj,max);
    		}
    			
    	}
    	if(!isExist){ //不存在马鞍点
    		printf("no
    ");
    	}
    }
    
    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] != ''){
    		ch = str[i];
    		if(isDigit(ch)){  //推断是否是数字
    			num = num*10 + ch - '0';  //累加数字
    			
    			if(str[i+1] != '')
    				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("
    ");
    	return 0;
    }
    



    转载请标明出处:牟尼的专栏 http://blog.csdn.net/u012027907


  • 相关阅读:
    CentOS8 安装 Java JDK
    小程序问题汇总
    CSS实现侧边栏固定宽度,内容栏自适应
    垂直居中总结
    移动端Web App自适应布局探索
    学习指南
    插件集
    移动端滑动事件
    网站收藏
    js void运用
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/6751707.html
Copyright © 2011-2022 走看看