#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. Redis 基本数据类型以及相应操作

    〇.常用命令 select <num> 选择库0~15 默认0号库 key * 查看当前库所有键(可以接正则表达式) exists <key> type <key> ...

  2. Django中的check指令和sqlmigrate指令

    官方文档的解释如下: Django 有一个自动执行数据库迁移并同步管理你的数据库结构的命令 - 这个命令是 migrate,我们马上就会接触它 - 但是首先,让我们看看迁移命令会执行哪些 SQL 语句 ...

  3. Qt核心剖析:信息隐藏

    原文 http://devbean.blog.51cto.com/448512/326686 (一) 如果你阅读了 Qt 的源代码,你会看到一堆奇奇怪怪的宏,例如 Q_D,Q_Q.我们的Qt源码之旅就 ...

  4. AS常用快捷键

    Alt+回车 导入包,自动修正 Ctrl+N 查找类 Ctrl+Shift+N 查找文件 Ctrl+Alt+L 格式化代码 Ctrl+Alt+O 优化导入的类和包 Alt+Insert 生成代码(如g ...

  5. php 下载word 含图片

      ob_start();//打开输出缓冲区 echo ' <html xmlns:o="urn:schemas-microsoft-com:office:office"xm ...

  6. .NET core 部署到Docker +Docker Protainer管理实现

    .NET core 部署到Docker +Docker Protainer管理实现 上次说到将.net core的应用程序发布到Linux中(https://www.cnblogs.com/Super ...

  7. GITlab安装、使用及新项目推送到gitlab

    ==================================================================================================== ...

  8. 粪发涂墙-Redis

    Redis的高并发和快速原因 1.redis是基于内存的,内存的读写速度非常快: 2.redis是单线程的,省去了很多上下文切换线程的时间: 3.redis使用多路复用技术,可以处理并发的连接.非阻塞 ...

  9. Spring5 of WebClient(转载)

    前言 Spring5带来了新的响应式web开发框架WebFlux,同时,也引入了新的HttpClient框架WebClient.WebClient是Spring5中引入的执行 HTTP 请求的非阻塞. ...

  10. sshpass远程登陆

    1,ssh ssh 端口为默认22的时候: sshpass -p 888888 scp -o StrictHostKeyChecking=no /root/images.zip root@21.1.9 ...