L2-2 你究竟有几个好妹妹

输入样例:

例如:

hmm
10
Zoehmm F 28 2001.01.01
hmmBeith F 18 2010.10.21
Zack M 35 1999.09.18
hmmAdam F 21 2010.10.21
Beithhmm F 21 2010.10.21
Chelse F 45 2005.12.03
DaisyHMM F 30 2008.08.05
Eston M 18 2015.03.04
hmmFrany F 8 2018.07.15
JackHM F 7 2017.09.11

输出样例:

输出:

6
Adam 21 2010.10.21
Beith 18 2010.10.21
Beith 21 2010.10.21
Daisy 30 2008.08.05
Frany 8 2018.07.15
Zoe 28 2001.01.01

参考代码:

#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e5 + 10;

struct HMM {
	string name;
	int age;
	string date;
};

int n , age;
vector<HMM>hmm;
string name , sex , date , flag;

string toLower(string s) {
	for(int i = 0 ; i < s.size() ; i++)
		s[i] = tolower(s[i]);
	return s;
}

bool isHmm(string &name) {
	string tname = toLower(name);
	int index = tname.find(flag);
	if(index == -1)
		return false;
		
	if(index == 0)
		name = name.substr(flag.size());
	else
		name = name.substr(0 , name.size() - flag.size());
	return true;
}

bool cmp(HMM a , HMM b) {
	if(a.name != b.name)
		return a.name < b.name;
	if(a.age != b.age)
		return a.age < b.age;
	return a.date < b.date;
}

int main() {
	cin>>flag>>n;
	flag = toLower(flag);
	
	while(n--) {
		cin>>name>>sex>>age>>date;
		if(sex == "F" && isHmm(name))
			hmm.push_back({name , age , date});
	}	
	
	sort(hmm.begin() , hmm.end() , cmp);
	
	cout<<hmm.size()<<endl;
	for(int i = 0 ; i < hmm.size() ; i++)
		cout<<hmm[i].name<<" "<<hmm[i].age<<" "<<hmm[i].date<<endl;
	return 0;
} 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

「江太白」

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

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

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

打赏作者

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

抵扣说明:

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

余额充值