#include<bits/stdc++.h>
using namespace std;
string s[100007];
set<int>st[100007][7];
int t[207];
int a[100007],b[100007][2],c[100007],d[100007][2];
int main(){
t['a']=1;
t['e']=2;
t['i']=3;
t['o']=4;
t['u']=5;
int n;
cin>>n;
for(int i=1;i<=n;++i){
cin>>s[i];
int cnt=0;
char last;
for(int j=0;j<s[i].length();++j){
if(s[i][j]=='a'||s[i][j]=='e'||s[i][j]=='i'||s[i][j]=='o'||s[i][j]=='u'){
cnt++;
last=s[i][j];
}
}
if(cnt){
st[cnt][t[last]].insert(i);
}
}
int cnt1=0,cnt2=0;
int num1=0,num2=0;
for(int i=1;i<=100000;++i){
num1=0;
for(int j=1;j<=5;++j){
num2=0;
for(auto it:st[i][j]){
a[++num2]=it;//将有i个元音字母并且结尾元音字母编号为j的字符串序号放进a数组中
}
for(int k=1;k<num2;k+=2){//将a数组中的字符串成双取出到b数组,他们都拥有相同的元音字母个数和最后一个字母
b[++cnt1][0]=a[k];
b[cnt1][1]=a[k+1];
}
if(num2&1)//a数组有一个余下的字符串序号
c[++num1]=a[num2];//c数组放成单的字符串序号,他们都拥有相同的元音字母个数i,却没有相同的结尾元音字母
}
for(int j=1;j<num1;j+=2){//将c数组中的字符串成双取出到d数组,他们都拥有相同的元音字母个数,结尾元音字母不同使得它们只能放在每行的第一个
d[++cnt2][0]=c[j];
d[cnt2][1]=c[j+1];
}
}
if(cnt1<=cnt2){//拥有相同元音字母个数的对数少于不同的
cout<<cnt1<<"\n";
for(int i=1;i<=cnt1;++i){
cout<<s[d[i][0]]<<" "<<s[b[i][0]]<<"\n";
cout<<s[d[i][1]]<<" "<<s[b[i][1]]<<"\n";
}
}
else{
int ans=cnt2+(cnt1-cnt2)/2;//拥有相同元音字母个数的对数较多,优先让它们和不同的进行搭配,再两两自成对
cout<<ans<<"\n";
for(int i=1;i<=cnt2;++i){
cout<<s[d[i][0]]<<" "<<s[b[i][0]]<<"\n";
cout<<s[d[i][1]]<<" "<<s[b[i][1]]<<"\n";
}
for(int i=cnt2+1;i<cnt1;i+=2){
cout<<s[b[i][0]]<<" "<<s[b[i+1][0]]<<"\n";
cout<<s[b[i][1]]<<" "<<s[b[i+1][1]]<<"\n";
}
}
return 0;
}

Codeforces Round #566 (Div. 2)C(字符串,SET)的更多相关文章

  1. Codeforces Round #566 (Div. 2)

    Codeforces Round #566 (Div. 2) A Filling Shapes 给定一个 \(3\times n\) 的网格,问使用 这样的占三个格子图形填充满整个网格的方案数 如果 ...

  2. Codeforces Round #410 (Div. 2)(A,字符串,水坑,B,暴力枚举,C,思维题,D,区间贪心)

    A. Mike and palindrome time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...

  3. Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质

    https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...

  4. Codeforces Round #329 (Div. 2)A 字符串处理

    A. 2Char time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  5. Codeforces Round #566 (Div. 2) C. Beautiful Lyrics

    链接: https://codeforces.com/contest/1182/problem/C 题意: You are given n words, each of which consists ...

  6. Codeforces Round #566 (Div. 2) B. Plus from Picture

    链接: https://codeforces.com/contest/1182/problem/B 题意: You have a given picture with size w×h. Determ ...

  7. Codeforces Round #566 (Div. 2) A. Filling Shapes

    链接: https://codeforces.com/contest/1182/problem/A 题意: You have a given integer n. Find the number of ...

  8. Product Oriented Recurrence(Codeforces Round #566 (Div. 2)E+矩阵快速幂+欧拉降幂)

    传送门 题目 \[ \begin{aligned} &f_n=c^{2*n-6}f_{n-1}f_{n-2}f_{n-3}&\\ \end{aligned} \] 思路 我们通过迭代发 ...

  9. Codeforces Round #566 (Div. 2)题解

    时间\(9.05\)好评 A Filling Shapes 宽度为\(3\),不能横向填 考虑纵向填,长度为\(2\)为一块,填法有两种 如果长度为奇数则显然无解,否则\(2^{n/2}\) B Pl ...

随机推荐

  1. 【转载】SpringMVC框架介绍

    转自:http://com-xpp.iteye.com/blog/1604183 SpringMVC框架图   SpringMVC接口解释   DispatcherServlet接口: Spring提 ...

  2. pyppeteer硬钢掉淘宝登入的滑块验证

    完整代码我也不好公布,我可以给你们思路,以及部分代码动动脑子看看文档应该也能搞定 一.初始化Chromium浏览器相关属性 browser = await pyppeteer.launch({'hea ...

  3. 微信小程序中showToast 提示

    icon可以none,也可以 success wx.showToast({ title: '已提交', icon: 'success', duration: 2000 })

  4. vue音乐播放器

    利用vue写一个简单的音乐播放器,包括功能有歌曲搜索.歌曲播放.歌曲封面.歌曲评论.播放动画.mv播放六个功能. <template> <div class="wrap&q ...

  5. matplotlib添加坐标轴实现性格测试可视化

    一张图展示最终效果 皮一下很开心,标签名肯定不是用户想要的,所以在这里尝试了定制化功能 功能&方法: 定制化标签名/标签数量(4个/5个).实现方法:在第一个界面点击cancel按钮,进入修改 ...

  6. Spring - jdbcTemplate - 调试代码: PreparedStatementCreator 生成的语句, update 之后没有 自增id, 已解决

    1. 概述 解决 jdbcTemplate 下, update 结果不带 自增id 的问题 2. 场景 看书 Spring in Action 5th 3.1.4 listing 3.10 saveT ...

  7. 【音乐欣赏】《Wrong》 - Far Out / Emilia Ali

    曲名:Wrong 作者:Far Out / Emilia Ali [00:16.03]Ride body on mine [00:18.07]Griping your waist as I was o ...

  8. Java中正负数的存储方式-正码 反码和补码

    Java中正负数的存储方式-正码 反码和补码 正码 我们以int 为例,一个int占用4个byte,32bits 0 存在内存上为 00000000 00000000 00000000 0000000 ...

  9. codeforces Beautiful Numbers

    来源:http://codeforces.com/problemset/problem/1265/B   B. Beautiful Numbers   You are given a permutat ...

  10. RabbitMQ连接池、生产者、消费者实例

    1.本文分享RabbitMQ的工具类,经过实际项目长期测试,在此分享给发家,各位大神有什么建议请指正 !!! 2.下面是链接池主要代码: import java.util.HashMap; impor ...