zoukankan      html  css  js  c++  java
  • 题目(13)答案

    #include <iostream>
    #include <string>
    #include "stdio.h"
    #include <iomanip>
    
    using namespace std;
    
    struct picture{
    	string gender;
    	float high;
    };
    
    int main()
    {
    	int n;
    	picture a[1001];
    	double male[1001], female[1001];
    	int malen, femalen;
    	malen = femalen = 0;
    	std::cin >> n;
    	for(int i = 0; i < n; i++)
    	{
    		std::cin >> a[i].gender;
    		std::cin >> a[i].high;
    		//male female
    		if(a[i].gender == "male"){
    			male[malen] = a[i].high;
    			malen++;
    		}
    		else if(a[i].gender == "female"){
    			female[femalen] = a[i].high;
    			femalen++;
    		}
    	}
    	/*
    	6
    	male 1.72
    	male 1.78
    	female 1.61
    	male 1.65
    	female 1.70
    	female 1.56
    	*/
    	for(int i = 0; i < malen; i++)
    		for(int j = i; j < malen; j++)
    			if(male[i] > male[j])
    				swap(male[i], male[j]);
    	for(int i = 0; i < femalen; i++)
    		for(int j = i; j < femalen; j++)
    			if(female[i] < female[j])
    				swap(female[i], female[j]);
    	for(int i = 0; i < malen; i++)
    		std::cout << std::fixed << std::setprecision(2) << male[i] << " ";
    	for(int i = 0; i < femalen; i++)
    		std::cout << std::fixed << std::setprecision(2) << female[i] << " ";
    	cout << endl;
    	 
    	printf("
    ");
    	return 0;
    }
    
    std::
    

    其实没什么用,要是不要std::
    就必须写上

    using namespace std;
    

    struct 是一个结构体
    有一个int类型变量
    和一个string类型变量。


  • 相关阅读:
    安卓
    查询
    数据库

    phpcms后台获取当前登录账号的数据的代码:
    phpcms后台批量上传添加图片文章方法详解(一)
    phpcms头部代码详细分析
    网站迁移的方法
    phpcms 修改域名
    外网访问我们配置好的WampServer服务器
  • 原文地址:https://www.cnblogs.com/coding365/p/12872408.html
Copyright © 2011-2022 走看看