A.扫雷
暴力模拟AC:
cpp
#include<iostream>
using namespace std;
const int N=105;
int n,m,map[N][N],ans[N][N];
int dx[8]={-1,-1,0,1,1,1,0,-1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
int count(int x,int y){
int cnt=0;
for(int i=0;i<8;i++){
int xx=x+dx[i];
int yy=y+dy[i];
if(xx>0&&xx<=n&&yy>0&&yy<=m&&map[xx][yy]==1) cnt++;
}
return cnt;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>map[i][j];
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++){
if(map[i][j]==0) ans[i][j]=count(i,j);
else ans[i][j]=9;
}
}
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++){
cout<<ans[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
B.九进制转十进制
cpp
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int ans=0;
ans=2*pow(9,3)+2*pow(9,1)+2;
cout<<ans<<endl;
return 0;
}
C.顺子日期
cpp
#include<iostream>
using namespace std;
int ans;
int months[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int a[8];
bool check(int date){
int m=date%10000/100;
int d=date%100;
if(!m||!d||m>12) return false;
if(d>months[m]) return false;
return true;
}
bool judge(int num){
for(int i=7;i>=0;i--){
a[i]=num%10;
num/=10;
}
for(int i=0;i<6;i++){
int j=i+1,k=i+2;
if(a[j]==a[i]+1&&a[j]==a[k]-1) return true;
}
return false;
}
int main(){
for(int i=20220101;i<=20221231;i++) if(check(i)&&judge(i)) ans++;
cout<<ans<<endl;
return 0;
}