本人菜鸡,写的不对之处还望各位大佬指正。
题目只有印象中的一点,具体还请自行百度,在这里说声抱歉
找最长不重复的字符串
package toutiao;
import java.util.Scanner;
public class toutiao_2019_3_2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
int num = 0;//计数
int[][] ch = new int[i][i];
for(int x=0;x<ch.length;x++) {
for(int y=0;y<ch[0].length;y++) {
ch[x][y] = sc.nextInt();
}
}
for(int x=0;x<i;x++) {
for(int y=0;y<i;y++) {
if(ch[x][y]==1) {
num++;
}
}
}
System.out.println(num);
for(int x=0;x<i-1;x++) {
int y = 0;
for(;y<i-1;y++) {
if(ch[x][y]==1&&ch[x][y+1]==1||ch[x][y]==1&&1==ch[x+1][y]) {
num--;
}
}
}
System.out.println(num);
}
}