UVa12541 - Birthdates(排序)

Write a program to identify the youngest person and the oldest person in a class.
Input
The number n (1 n 100) in the rst line determines the number of people in a class. The following
n lines contain person's name and his/her birthdate.
The information in each line is of this format:
personN ame dd mm yyyy
where personN ame is a single word less than 15 letters, dd mm yyyy are date, month and year of the
birthdate.
Suppose that no one has the same name or the same birthdate.
Output
Print out 2 lines containing the name of youngest person and oldest person, respectively.
Sample Input
5
Mickey 1 10 1991
Alice 30 12 1990
Tom 15 8 1993
Jerry 18 9 1990
Garfield 20 9 1990
Sample Output
Tom
Jerry

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>

using namespace std;

const int N = 20;

struct Person
{
    string name;
    int year, month, day;

    bool operator < (const Person &other) const
    {
        if (year != other.year) return year > other.year;

        if (month != other.month) return month > other.month;

        if (day != other.day) return day > other.day;

        return name < other.name;
    }
};

vector<Person> persons;

void input();
void solve();


int main()
{
#ifndef ONLINE_JUDGE
    freopen("e:\\uva_in.txt", "r", stdin);
#endif

    input();
    solve();

    return 0;
}

void input()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        char name[N];
        int d, m, y;
        scanf("%s%d%d%d", name, &d, &m, &y);
        persons.push_back((Person){name, y, m, d});
    }
}



void solve()
{
    sort(persons.begin(), persons.end());

    printf("%s\n%s\n", persons.front().name.c_str(), persons.back().name.c_str());
}


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是一个可能的MATLAB代码实现: 1. 以格式“月月日日”统计班上同学出生日期,查找该日期在圆周率前10e6位首次出现的位次,记班上所有学生对应位次中第二个位次到数据集X: ```matlab % 读取圆周率数据 pi_str = fileread('pi.txt'); % 提取前10e6位数字 pi_digits = str2double(pi_str(1:10^6)); % 统计班上同学的出生日期,并转化为“月月日日”格式 birthdates = [19900101, 19910203, 19920305, ...]; % 假设有若干位同学 birthdates_str = datestr(birthdates, 'mmdd'); % 查找出生日期在圆周率中的位置,并记录每个同学对应的位置 X = NaN(size(birthdates)); for i = 1:length(birthdates_str) pos = strfind(pi_str, birthdates_str(i)); if ~isempty(pos) X(i) = pos(1) + 1; % 注意MATLAB中字符串下标从1开始,加1表示跳过小数点 end end % 取每个同学对应位置的第二个数字,作为数据集X X = str2double(arrayfun(@(pos) pi_str(pos+1), X(~isnan(X)))); ``` 2. 在置信水平1%、5%、15%上检测数据集X是否构成正态分布: ```matlab % 绘制正态概率图 figure; normplot(X); % 进行Kolmogorov-Smirnov检验 alpha = [0.01, 0.05, 0.15]; for i = 1:length(alpha) [h, p] = kstest(X, 'Alpha', alpha(i)); if h fprintf('At %d%% significance level, X is not normally distributed (p = %f)\n', 100*(1-alpha(i)), p); else fprintf('At %d%% significance level, X is normally distributed (p = %f)\n', 100*(1-alpha(i)), p); end end ``` 3. 设数据集X构成正态分布,估计参数均值与方差,并分别记为μ与σ: ```matlab % 估计均值和方差 mu = mean(X); sigma = std(X); fprintf('mu = %f, sigma = %f\n', mu, sigma); ``` 4. 假设数据集Y也是均值为μ的正态分布,检验其方差是否为σ: ```matlab % 假设数据集Y也是均值为mu的正态分布,生成一个随机样本 Y = normrnd(mu, 1, size(X)); % 进行方差齐性检验 alpha = [0.01, 0.05, 0.15]; for i = 1:length(alpha) [h, p] = vartestn(X, Y, 'Alpha', alpha(i)); if h fprintf('At %d%% significance level, Y does not have the same variance as X (p = %f)\n', 100*(1-alpha(i)), p); else fprintf('At %d%% significance level, Y has the same variance as X (p = %f)\n', 100*(1-alpha(i)), p); end end ``` 5. 假设数据集Y也是方差为σ的正态分布,检验其均值是否为μ: ```matlab % 假设数据集Y也是方差为sigma的正态分布,生成一个随机样本 Y = normrnd(mu, sigma, size(X)); % 进行双样本t检验 alpha = [0.01, 0.05, 0.15]; for i = 1:length(alpha) [h, p] = ttest2(X, Y, 'Alpha', alpha(i)); if h fprintf('At %d%% significance level, Y does not have the same mean as X (p = %f)\n', 100*(1-alpha(i)), p); else fprintf('At %d%% significance level, Y has the same mean as X (p = %f)\n', 100*(1-alpha(i)), p); end end ``` 6. 利用秩和检验检测数据集X与数据集Y是否存在显著差异: ```matlab % 进行秩和检验 [p, h] = ranksum(X, Y); if h fprintf('X and Y have significantly different medians (p = %f)\n', p); else fprintf('X and Y have similar medians (p = %f)\n', p); end ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kgduu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值