• 题目(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类型变量。


  • 相关阅读:
    Web后门工具WeBaCoo
    苹果内存取证工具volafox
    PlayMaker GUI的Normalized
    Arduino可穿戴教程之第一个程序——选择端口(三)
    缩略图信息提取工具vinetto
    jquery的defer
    toDo
    瀑布流案例
    js基本知识6
    js基本知识5
  • 原文地址:https://www.cnblogs.com/coding365/p/12872408.html
Copyright © 2020-2023  润新知