中国MOOC很舒服。
模板与泛型
当重复使用某段代码 拷贝代码不利于debug
c++:推出模板 语法template <class T>;class xxx Table
Java
class xxx<T>{
public T a;
public T b;//不能实例化
xxx<Intger> t =new xxx <>();
Arraylist(顺序表,容器类)
ArrayList<stu> al=new ArrayList<>();
函数与递归
函数的定义
先写调用
定义函数(考虑返回什么 传入的参数是什么)
Java : 什么都不能脱离类
考虑 static(静态成员变量 方法)
递归(开辟新的内存空间 所以不能滥用(效率,栈溢出)) 自己调用自己 小窍诀 靠信念哈哈哈
先写调用 1.明确函数要干嘛
2.寻找递归结束条件
3.找出等价关系
数组
c语言 定义数组: int array [N]; int *array =malloc();
*(array+1)
Java 数组定义 引用型 int [] array =new int(Type) [10];
二维数组的应用
大炮打蚊子
#include<stdio.h>
int baord[20][20];//全局数组
int M,N; //读入 mn
int bang(int x,int y,int kill){
if((x>=0&&x<M)&&(y>=0&&y<N)&&baord[x][y]>0){
baord[x][y]-=kill;
if(baord[x][y]<=0) return 1;
else{
return 0;
}
}else{
return 0;
}
}
int main(){
scanf("%d%d",&M,&N);
getchar();
for(int i=0;i<M;i++){
for(int j=0;j<N;j++){
baord[i][j]=getchar()=='0'?0:2;
}
getchar();
}
int k;
scanf("%d",&k);
for(int i =0;i<k;i++){
int x,y;
scanf("%d%d",&x,&y);
int count;
count =0;
count+=bang(x,y,2);
count+=bang(x+1,y,1);
count+=bang(x-1,y,1);
count+=bang(x,y-1,1);
count+=bang(x,y+1,1);
printf("%d\n",count);
}
return 0;
}
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner scanner = new Scanner(System.in);
int n,m;
n = scanner.nextInt();
m = scanner.nextInt();
String [] mapp;
mapp = new String[m];
for(int i = 0; i < n; i ++)
mapp[i] = scanner.next();
int [][] index;
index = new int [25][25];
int cnts = 0;
for(int i = 0; i < n; i ++)
{
for(int j = 0; j < m; j ++)
{
if(String.valueOf(mapp[i].charAt(j)).equals("#"))
{
index[i][j] = 2;
}
else
{
index[i][j] = 0;
cnts++;
}
}
}
int k;
k = scanner.nextInt();
for(int t = 0; t < k; t ++)
{
int a,b;
a = scanner.nextInt();
b = scanner.nextInt();
if(index[a][b]!=0)
index[a][b] = 0;
if(a+1<n&&index[a+1][b]!=0)
index[a+1][b]--;
if(a-1>=0&&index[a-1][b]!=0)
index[a-1][b]--;
if(b-1>=0&&index[a][b-1]!=0)
index[a][b-1]--;
if(b+1<m&&index[a][b+1]!=0)
index[a][b+1]--;
int temp = 0;
for(int i = 0; i < n; i ++)
for(int j = 0; j < m; j ++)
if(index[i][j]==0)
temp ++;
System.out.println(temp-cnts);
cnts = temp;
}
scanner.close();
}
}
————————————————
版权声明:本文为CSDN博主「少女情怀总是诗mmm」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qiulianshaonv_wjm/article/details/89151322