POJ1002
来源:互联网 发布:java 输出参数 out 编辑:程序博客网 时间:2024/06/10 05:59
起初没理解清本题的意思,然后在网上查了一下,查到了其他人写的源代码,本来想着参考参考,一不小心抄了一大部分,仅作为一个例题学习学习吧:
import java.io.*;
import java.util.*;
import java.io.IOException;
public class Main{
public static void main(String[] args){
Scanner cin=new Scanner(System.in);
String s=cin.nextLine();
int a=Integer.valueOf(s);
int index;
String[] str=new String[a];
for(int i=0;i<a;i++){
str[i]=cin.nextLine();
char[] chars=new char[7];
index = 0;
for(int j=0;j<str[i].length();j++){
if(str[i].charAt(j)=='-'){
continue;
}else{
char t=str[i].charAt(j);
if(t>='0'&&t<='9'){
chars[index++]=t;
}else{
chars[index++]=returnValue(t);
}
}
}
str[i]=String.valueOf(chars);
}
Arrays.sort(str);
int num=1;
String temp=str[0];
boolean b=false;
for(int i=1;i<a;i++){
if(temp.equals(str[i])){
num++;
if(i==a-1){
if(num>1){
System.out.println(temp.substring(0,3)+"-"+temp.substring(3)+" "+num);
b=true;
}
}
}else{
if(num>1){
System.out.println(temp.substring(0,3)+"-"+temp.substring(3)+" "+num);
b=true;
temp=str[i];
num=1;
}else{
temp=str[i];
num=1;
}
}
}
if(!b){
System.out.println("No duplicates.");
}
}
public static char returnValue(char c){
if(c>=65&&c<=67){
return '2';
}else if(c>=68&&c<=70){
return '3';
}else if(c>=71&&c<=73){
return '4';
}else if(c>=74&&c<=76){
return '5';
}else if(c>=77&&c<=79){
return '6';
}else if(c>=80&&c<=83){
return '7';
}else if(c>=84&&c<=86){
return '8';
}else if(c>=87&&c<=89){
return '9';
}else{
return '0';
}
}
}
- POJ1002
- POJ1002
- poj1002
- poj1002
- poj1002
- poj1002
- poj1002
- POJ1002
- poj1002
- POJ1002
- POJ1002
- POJ1002
- poj1002
- POJ1002
- POJ1002
- poj1002
- poj1002
- POJ1002
- Android的Activity屏幕切换动画-左右滑动深入与实战
- 《计算机教育》专题报道:充满快乐的提高班
- 基于压缩传感的脉冲GPR成像技术研究(硕士学位论文初稿20111230)
- jQuery 导航菜单点击伸缩展开效果的JS特效
- Java 使用poi导入excel,结合xml文件进行数据验证的例子(增加了jar包)
- POJ1002
- 关于字符串驻留
- 困扰我的多线程
- 字符串分段、替换
- JDBC连接SQL Server 2008 R2时遇到的常见问题集解
- @dynamic
- hash表 c语言实现
- oracle Pipelined Table Functions 的使用 (包含split函数的示例)
- 《计算机教育》专题报道:阶梯式教学法