• 【915程序设计】16西交大软件专硕915程序设计真题讲解


    1. 字符串

    #include
    using namespace std;
    
    string str;
    
    int main(){
    	cin>>str;
    	for(string::iterator i=str.begin();i!=str.end();){
    		if(*i>='0'&&*i<='9'){
    			i=str.erase(i);
    		}else{
    			++i;
    		}
    	}
    	cout<<str;
    	return 0;
    } 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    在这里插入图片描述

    2. 统计

    #include
    using namespace std;
    
    int n,m; 
    
    int f(int n,int m){
    	int cnt=0;
    	if(!(0<=n&&n<=9)){
    		return -1;
    	}
    	while(m){
    		if(m%10==n){
    			++cnt;
    		}
    		m/=10;
    	}
    	return cnt;
    }
    
    int main(){
    	cin>>n>>m;
    	cout<<f(n,m);
    	return 0;
    } 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

    在这里插入图片描述

    3. 学生上课率旷课率统计

    #include
    using namespace std;
    
    int stuNum,clazzNum;
    
    // 注意map >
    // 注意map >
    // 注意map >
    map<string,vector<string> > students;
    
    
    void countOne(string no){
    	vector<string> status=students[no];
    	double cnt1=0,cnt2=0;
    	for(int i=0;i<clazzNum;++i){
    		if(status[i]=="正常"||status[i]=="迟到"){
    			++cnt1;
    		}else if(status[i]=="旷课"){
    			++cnt2; 
    		}
    	}
    	cout<<no<<"\t上课率: "<<cnt1/clazzNum*100<<"%\t旷课率: "<<cnt2/clazzNum*100<<"%"<<endl;
    }
    
    void countAll(){
    	for(map<string,vector<string> >::iterator i=students.begin();i!=students.end();++i){
    		countOne(i->first);
    	}
    }
    
    int main(){
    	cin>>stuNum>>clazzNum;
    	for(int i=0;i<stuNum;++i){
    		string no;
    		vector<string> status;
    		cin>>no;
    		for(int j=0;j<clazzNum;++j){
    			string temp;
    			cin>>temp;
    			status.push_back(temp);
    		}
    		students[no]=status;
    	}
    	countAll();
    	return 0;
    } 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46

    在这里插入图片描述

  • 相关阅读:
    linux操作系统虚拟机的环境配置
    多元时间序列特征工程的指南
    深入了解Java位运算符
    什么是云原生的应用?
    (附源码)springboot毕业生弃置物品交易系统 毕业设计 231151
    sqoop学习
    探索Python中的装饰器
    恒创科技:IPv4 和 IPv6 之间的主要区别
    Seata分布式事务
    gcc编译过程
  • 原文地址:https://blog.csdn.net/weixin_45953673/article/details/126833793