五子棋_电话号码
【摘要】 五子棋五子棋import java.util.*;public class Main { //上下左右...八个方位!!!! static int[][] direction = {{0, 1}, {0, - 1}, {1, 0}, { - 1, 0}, {1, 1}, {1, - 1}, { - 1, 1}, { - 1, - 1}}; public static void mai...
五子棋
import java.util.*;
public class Main {
//上下左右...八个方位!!!!
static int[][] direction = {{0, 1}, {0, - 1}, {1, 0}, { - 1, 0}, {1, 1}, {1, - 1}, { - 1, 1}, { - 1, - 1}};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
Character[][] map = new Character[20][20];
for (int i = 0; i < 20; i ++ ) {
String s = sc.next();
for (int j = 0; j < 20; j ++ ) {
map[i][j] = s.charAt(j);
}
}
if(check(map)) System.out.println("Yes");
else System.out.println("No");
}
}
public static boolean check(Character[][] map) {
for (int i = 0; i < 20; i ++ ) {
for (int j = 0; j < 20; j ++ ) {
if(map[i][j] == '*' || map[i][j] == '+') {
for (int k = 0; k < 8; k ++ ) {
int count = 1;
int x = i + direction[k][0];
int y = j + direction[k][1];
while (x >= 0 && x < 20 && y >= 0 && y < 20 && map[x][y] == map[i][j]) {
count ++ ;
x += direction[k][0];
y += direction[k][1];
}
if(count == 5) return true;
}
}
}
}
return false;
}
}
电话号码
import java.util.*;
public class Main{
public static void main(String[] args){
String symbol="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
String number="222333444555666777788899991234567890";
//这里用两张表进行查询!
Scanner scanner=new Scanner(System.in);
while(scanner.hasNext()){
int n=scanner.nextInt();
ArrayList<String> arrayList=new ArrayList<String>();
for(int i=0;i<n;i++){
String str=scanner.next();
str=str.replace("-","");
String result="";
for(int j=0;j<7;j++){
//采用字符串拼接,开销大!
result+=number.charAt(symbol.indexOf(str.charAt(j)+""));
}
result=result.substring(0,3)+"-"+result.substring(3,7);
if(!arrayList.contains(result)) //去重!
arrayList.add(result);
}
Collections.sort(arrayList);//集合排序!! Collections.sort()
for(int j=0;j<arrayList.size();j++){
System.out.println(arrayList.get(j));
}
System.out.println();
}
}
}
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)