UVALive 5739|User Names|模拟
来源:互联网 发布:苹果手机能编程吗 编辑:程序博客网 时间:2024/05/17 01:00
一个大学电脑系统通过下面的规则确定学生的用户名:
1. 用户名长度不超过
2. 用户名第一个字符为这个人的first name,转换成小写,忽略非字母的字符
3. 把这个人的last name加到用户名后面(小写),如果超出
4. 如果规则1~3产生的用户名在数据库中已经存在,若用户名长度为
5. 如果规则1~4产生的用户名在数据库中已经存在,若用户名长度为
6. 假设上述规则能覆盖所有输入情况。
输入
输入有多组数据,对于每组数据,第一行2个正整数
输出
对于每组数据,第一行包含数据组序号,接下来几行每行一个用户名,对应输入的学生姓名。
样例输入
2 6Jenny AxChristos H Papadimitriou11 8Jean-Marie d’ArbouxJean-Marie A d’ArbouxJean-Marie B d’ArbouxJean-Marie C d’ArbouxJean-Marie D d’ArbouxJean-Marie D d’ArbouxJean-Marie F d’ArbouxJean-Marie G d’ArbouxJean-Marie H d’ArbouxJean-Marie I d’ArbouxJean-Marie J d’Arboux11 9Jean-Marie d’ArbouxJean-Marie A d’ArbouxJean-Marie B d’ArbouxJean-Marie C d’ArbouxJean-Marie D d’ArbouxJean-Marie D d’ArbouxJean-Marie F d’ArbouxJean-Marie G d’ArbouxJean-Marie H d’ArbouxJean-Marie I d’ArbouxJean-Marie J d’Arboux0 0
样例输出
Case 1jaxcpapadCase 2jdarbouxjdarbou1jdarbou2jdarbou3jdarbou4jdarbou5jdarbou6jdarbou7jdarbou8jdarbou9jdarbo10Case 3jdarbouxjdarboux1jdarboux2jdarboux3jdarboux4jdarboux5jdarboux6jdarboux7jdarboux8jdarboux9jdarbou10
题解
Java大法好
import java.util.*;import java.util.stream.Collectors;public class p5739 { public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(System.in); int kase = 0; while (true) { int n = scanner.nextInt(), maxlen = scanner.nextInt(); if (n == 0 && maxlen == 0) break; scanner.nextLine(); HashSet<String> set = new HashSet<>(); System.out.printf("Case %d\n", ++kase); while (--n >= 0) { String name = scanner.nextLine(); String[] names = name.split(" "); String first = names[0]; String last = names[names.length - 1]; String original = new StringBuilder().appendCodePoint(first.toLowerCase().chars() .filter(Character::isAlphabetic) .findFirst().getAsInt()) .append(last.toLowerCase().codePoints().filter(Character::isAlphabetic).collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append) .toString()).toString(); if (original.length() > maxlen) original = original.substring(0, maxlen); String ans = original; int len = 1, roll = 0, sq = 1; while (set.contains(ans)) { ++roll; if (roll >= sq * 10) { ++len; sq *= 10; } if (maxlen - len > original.length()) ans = original + roll; else ans = original.substring(0, maxlen - len) + roll; } set.add(ans); System.out.println(ans); } } }}
阅读全文
0 0
- UVALive 5739|User Names|模拟
- UVALive 5739 User Names
- HDU 4167 User Names
- HDU 4167 User Names
- HDU 4167 User Names【string stl】
- UVALive 3497 brainfuck [模拟]
- UVALive 4723 水模拟
- UVALive 6833 (模拟 水~)
- UVALive 7503--模拟
- UValive 7269 (模拟)
- UVALive 6833【模拟】
- UVALive 7327【模拟】
- UVALive 7608Robot(模拟)
- UVALive 7752 模拟
- names
- 【模拟】 UVALive 4168 Lampyridae Teleportae
- UvaLive--6664--Clock Hands【模拟】
- UVALive 4887 Soccer 状压+模拟
- 面试中如何回答HashMap的工作原理
- [思维导图]Java中异常的分类整理
- 文章标题
- 打印机打印列队中打印状态为错误的解决方式之一
- webService笔记(2)---入门示例
- UVALive 5739|User Names|模拟
- 每天一个linux命令(14):head 命令
- Vue小Demo,仿lofter移动端
- j2me中遇到的两个错误
- Ajax原生实例
- 伪代码规范
- 数据结构与算法之五(递归与递归消除)
- 如何在googleplay上发布应用?
- 2017.10.23工作日记