求助站外题(急)
  • 板块题目总版
  • 楼主Ben幻影
  • 当前回复13
  • 已保存回复13
  • 发布时间2021/10/17 19:13
  • 上次更新2023/11/4 03:27:56
查看原帖
求助站外题(急)
354482
Ben幻影楼主2021/10/17 19:13

ybt上的题

link

#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,y,ans=0;
	cin>>x>>y;
	if(x==1){
		cin>>x;
		cout<<x;
		return 0;
	}
	int **a=new int *[x];
	for(int i=0;i<x;i++){
		a[i]=new int[y];
	}
	for(int i=0;i<x;i++){
		for(int j=0;j<y;j++){
			cin>>a[i][j];
		}
	} 
	for(int i=0;i<x;i++){
		ans+=a[0][i]+a[x-1][i];
	}
	for(int i=0;i<y;i++){
		ans+=a[i][0]+a[i][y-1];
	}
	ans-=a[0][0]+a[0][y-1]+a[x-1][0]+a[x-1][y-1] ; 
	cout<<ans<<endl;
	for(int i=0;i<x;i++){
		delete[] a[i];
	}
	delete[] a; 
	return 0;
}
2021/10/17 19:13
加载中...