关于蓝桥杯的一道题
来源:互联网 发布:乐语软件下载 编辑:程序博客网 时间:2024/05/21 09:04
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
public class Main {
public static char getNum(char c) {
if (Character.isDigit(c)) {
return c;
}
if (c == 'A' || c == 'B' || c == 'C') {
return '2';
}
if (c == 'D' || c == 'E' || c == 'F') {
return '3';
}
if (c == 'G' || c == 'H' || c == 'I') {
return '4';
}
if (c == 'J' || c == 'K' || c == 'L') {
return '5';
}
if (c == 'M' || c == 'N' || c == 'O') {
return '6';
}
if (c == 'P' || c == 'R' || c == 'S') {
return '7';
}
if (c == 'T' || c == 'U' || c == 'V') {
return '8';
}
if (c == 'W' || c == 'X' || c == 'Y') {
return '9';
}
return '#';
}
public static void main(String[] args) throws IOException {
DataInputStream scan = new DataInputStream(new BufferedInputStream(System.in));
Map< String, Integer> tm = new TreeMap();
int n = Integer.parseInt(scan.readLine().trim());
for (int i = 0; i < n; i++) {
String s = scan.readLine().replace("-", "");
StringBuilder sb = new StringBuilder();
for (int k = 0; k < s.length(); k++) {
char c = getNum(s.charAt(k));
if (Character.isDigit(c)) {
sb.append(c);
}
}
String result = sb.toString().substring(0, 3) + '-' + sb.toString().substring(3);
if (tm.containsKey(result)) {
int count = tm.get(result) + 1;
tm.put(result, count);
} else {
tm.put(result, 1);
}
}
Set se = tm.keySet();
Iterator it = se.iterator();
boolean flag = false;
while (it.hasNext()) {
String s = it.next().toString();
int count = tm.get(s);
if (count > 1) {
flag = true;
System.out.println(s + " " + count);
}
}
if (!flag) {
System.out.println("No duplicates. ");
}
}
}
import java.io.DataInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
public class Main {
public static char getNum(char c) {
if (Character.isDigit(c)) {
return c;
}
if (c == 'A' || c == 'B' || c == 'C') {
return '2';
}
if (c == 'D' || c == 'E' || c == 'F') {
return '3';
}
if (c == 'G' || c == 'H' || c == 'I') {
return '4';
}
if (c == 'J' || c == 'K' || c == 'L') {
return '5';
}
if (c == 'M' || c == 'N' || c == 'O') {
return '6';
}
if (c == 'P' || c == 'R' || c == 'S') {
return '7';
}
if (c == 'T' || c == 'U' || c == 'V') {
return '8';
}
if (c == 'W' || c == 'X' || c == 'Y') {
return '9';
}
return '#';
}
public static void main(String[] args) throws IOException {
DataInputStream scan = new DataInputStream(new BufferedInputStream(System.in));
Map< String, Integer> tm = new TreeMap();
int n = Integer.parseInt(scan.readLine().trim());
for (int i = 0; i < n; i++) {
String s = scan.readLine().replace("-", "");
StringBuilder sb = new StringBuilder();
for (int k = 0; k < s.length(); k++) {
char c = getNum(s.charAt(k));
if (Character.isDigit(c)) {
sb.append(c);
}
}
String result = sb.toString().substring(0, 3) + '-' + sb.toString().substring(3);
if (tm.containsKey(result)) {
int count = tm.get(result) + 1;
tm.put(result, count);
} else {
tm.put(result, 1);
}
}
Set se = tm.keySet();
Iterator it = se.iterator();
boolean flag = false;
while (it.hasNext()) {
String s = it.next().toString();
int count = tm.get(s);
if (count > 1) {
flag = true;
System.out.println(s + " " + count);
}
}
if (!flag) {
System.out.println("No duplicates. ");
}
}
}
0 0
- 关于蓝桥杯的一道题
- 关于数据库的一道题??
- 一道关于信号的题
- 关于继承的一道题
- 关于 static 的一道题
- 关于一道题的思考
- 关于C++的一道题
- 关于jvm的一道题
- 一道关于信号的题
- 关于textarea的一道题
- 一道简单的关于图的题
- 关于一道招聘题的分析
- 关于位运算的一道笔试题
- 一道关于字符串逆序的笔试题
- 另外一道关于Random的编程题
- 一道关于目录的编程题
- 关于printf类型提升的一道题
- Google关于递归的一道笔记题
- JAVA中clone方法详解
- 查询表结构sql
- 关于ns2添加mudp
- 162. Find Peak Element
- RVM baby 版本管理器
- 关于蓝桥杯的一道题
- Linx中C语言的文件操作(1)
- Android编程思想,面向对象程序设计第一篇——设计模式6个原则
- ns2.34添加mflood协议(泛洪协议)
- 数据结构期末总结
- dubbo分布式搭建
- [IDE工具配置]myeclipse 2014 专业版 安装 svn插件
- ZCMU—1159
- 使用Toolbar + DrawerLayout快速实现高大上菜单侧滑