[转]C#如何定义和使用数组

发布网友 发布时间:2022-04-20 06:21

我来回答

3个回答

热心网友 时间:2023-07-18 22:48

#include <stdio.h>
#define MAXNUM 101
#define JINWEI 1000000000
int i, j, k, l;
long m, n;
long ans[5];
int x_data[101][101];
long f[MAXNUM][MAXNUM][5];
long temp1[5], temp2[5];
FILE* fpin;
FILE* fpout;
void x_max(long *a, long *b);
void x_plus2(int a, int i, int j, long *temp);
void x_plusans(int i, int j);
void x_writeans();

int
main() {
fpin=fopen("game10.in","r");
fpout=fopen("game10.out","w");
if (!fpin || !fpout) {
return 0;
}

fscanf(fpin,"%ld%ld",&n,&m);
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
fscanf(fpin,"%d",&x_data[i][j]);
for (k = 1; k <= n; k++) {
memset(f, 0, sizeof(f));
for (l = 1; l <= m; l++) {
for (i = 1; i <= m - l + 1; i++) {
j = i + l - 1;
x_plus2(x_data[k][i], i + 1, j, temp1);
x_plus2(x_data[k][j], i, j - 1, temp2);
x_max(temp1, temp2);
}
x_plusans(1, m);
}
x_writeans();
}

return 0;
}
void
x_max(long *a, long *b) {
int k;
long temp[5];
for (k = 4; k >= 1; k--)
if (a[k] > b[k]) {
memcpy(temp, a, sizeof(temp));
break;
} else {
if (a[k] < b[k]) {
memcpy(temp, b, sizeof(temp));
break;
}
memcpy(temp, a, sizeof(temp));
}
for (k = 1; k <= 4; k++)
f[i][j][k] = temp[k];
}
void
x_plus2(int a, int i, int j, long *temp) {
int k;
memset(temp, 0, sizeof(temp));
temp[1] = (f[i][j][1] + a) << 1;
for (k = 2; k <= 4; k++) {
temp[k] = temp[k - 1] / JINWEI + (f[i][j][k] << 1);
temp[k - 1] = temp[k - 1] % JINWEI;
}
}
void
x_plusans(int i, int j) {
int k;
for (k = 1; k <= 4; k++) {
ans[k] = ans[k] + f[i][j][k];
if (ans[k] >= JINWEI) {
ans[k + 1] = ans[k + 1] + ans[k] / JINWEI;
ans[k] = ans[k] % JINWEI;
}
}
}
void
x_writeans() {
int k, j;
long maxnum;
maxnum = JINWEI / 10;
for (i = 4; i >= 1; i--)
if (ans[i] != 0) {
fprintf(fpout,"%ld",ans[i]);
break;
}
if (i == 1 && ans[i] == 0)
fprintf(fpout,"%c",'0');
for (k = i - 1; k >= 1; k--) {
for (j = 1; j <= 8; j++) {
if (ans[k] / maxnum == 0)
fprintf(fpout,"%c",'0');
maxnum /= 10;
}
fprintf(fpout,"%ld",ans[k]);
maxnum = JINWEI / 10;
}
fprintf(fpout,"\n");
}

热心网友 时间:2023-07-18 22:48

#include <stdio.h>
#define MAXNUM 101
#define JINWEI 1000000000
int i,j,k,l;
long m,n;
long ans[5];
int x_data[101][101];
long f[MAXNUM][MAXNUM][5];
long temp1[5],temp2[5];

void x_max(long *a,long *b);
void x_plus2(int a,int i,int j,long *temp);
void x_plusans(int i,int j);
void x_writeans();

int main()
{
freopen("game10.in","r",stdin);
freopen("game10.out","w",stdout);
scanf("%ld%ld",&n,&m);
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
scanf("%d",&x_data[i][j]);
for (k=1;k<=n;k++)
{
memset(f,0,sizeof(f));
for (l=1;l<=m;l++)
{
for (i=1;i<=m-l+1;i++)
{
j=i+l-1;
x_plus2(x_data[k][i],i+1,j,temp1);
x_plus2(x_data[k][j],i,j-1,temp2);
x_max(temp1,temp2);
// { f[i,j]:=max(2*(data[k,i]+f[i+1,j]),2*(data[k,j]+f[i,j-1]));}
}
x_plusans(1,m);
}
x_writeans();
}

return 0;
}
void x_max(long *a,long *b)
{
int k;
long temp[5];
for (k=4;k>=1;k--)
{
if (a[k]>b[k])
{
memcpy(temp,a,sizeof(temp));
break;
}
else
{
if (a[k]<b[k])
{
memcpy(temp,b,sizeof(temp));
break;
}
memcpy(temp,a,sizeof(temp));
}
}
for (k=1;k<=4;k++)
f[i][j][k]=temp[k];
}
void x_plus2(int a,int i,int j,long *temp)
{
int k;
memset(temp,0,sizeof(temp));
temp[1]=(f[i][j][1]+a)<<1;
for (k=2;k<=4;k++)
{
temp[k]=temp[k-1]/JINWEI+f[i][j][k]<<1;
temp[k-1]=temp[k-1]%JINWEI;
}
}
void x_plusans(int i,int j)
{
int k;
for (k=1;k<=4;k++)
{
ans[k]=ans[k]+f[i][j][k];
if (ans[k]>=JINWEI)
{
ans[k+1]=ans[k+1]+ans[k]/JINWEI;
ans[k]=ans[k]%JINWEI;
}
}
}
void x_writeans()
{
int k,j;
long maxnum;
maxnum=JINWEI/10;
for (i=4;i>=1;i--)
{
if (ans[i]!=0)
{
printf("%ld",ans[i]);
break;
}
}
if (i==1&&ans[i]==0)
{
printf("0");
}
for (k=i-1;k>=1;k--)
{
for (j=1;j<=8;j++)
{
if (ans[k]/maxnum==0)
{
printf("0");
}
maxnum/=10;
}
printf("%ld",ans[k]);
maxnum=JINWEI/10;
}
printf("\n");
}

热心网友 时间:2023-07-18 22:49

#include <stdio.h>
#include <memory.h>

#define MAXNUM 101
#define JINWEI 1000000000
int i,j,k,l;
long m,n;
long ans[5];
int x_data[101][101];
long f[MAXNUM][MAXNUM][5];
long temp1[5],temp2[5];

void x_max(long *a,long *b);
void x_plus2(int a,int i,int j,long *temp);
void x_plusans(int i,int j);
void x_writeans();

int main()
{
freopen("game10.in","r",stdin);
freopen("game10.out","w",stdout);

scanf("%ld,%ld",&n,&m);
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
scanf("%d",&x_data[i][j]);
for (k=1;k<=n;k++)
{
memset(f,0,sizeof(f));
for (l=1;l<=m;l++)
{
for (i=1;i<=m-l+1;i++)
{
j=i+l-1;
x_plus2(x_data[k][i],i+1,j,temp1);
x_plus2(x_data[k][j],i,j-1,temp2);
x_max(temp1,temp2);
// { f[i,j]:=max(2*(data[k,i]+f[i+1,j]),2*(data[k,j]+f[i,j-1]));}
}
x_plusans(1,m);
}
x_writeans();
}

return 0;
}
void x_max(long *a,long *b)
{
int k;
long temp[5];
for (k=4;k>=1;k--)
{
if (a[k]>b[k])
{
memcpy(temp,a,sizeof(temp));
break;
}
else
{
if (a[k]<b[k])
{
memcpy(temp,b,sizeof(temp));
break;
}
memcpy(temp,a,sizeof(temp));
}
}
for (k=1;k<=4;k++)
f[i][j][k]=temp[k];
}
void x_plus2(int a,int i,int j,long *temp)
{
int k;
memset(temp,0,sizeof(temp));
temp[1]=(f[i][j][1]+a)<<1;
for (k=2;k<=4;k++)
{
temp[k]=temp[k-1]/JINWEI+f[i][j][k]<<1;
temp[k-1]=temp[k-1]%JINWEI;
}
}
void x_plusans(int i,int j)
{
int k;
for (k=1;k<=4;k++)
{
ans[k]=ans[k]+f[i][j][k];
if (ans[k]>=JINWEI)
{
ans[k+1]=ans[k+1]+ans[k]/JINWEI;
ans[k]=ans[k]%JINWEI;
}
}
}
void x_writeans()
{
int k,j;
long maxnum;
maxnum=JINWEI/10;
for (i=4;i>=1;i--)
{
if (ans[i]!=0)
{
printf("%ld",ans[i]);
break;
}
}
if (i==1&&ans[i]==0)
{
printf("0");
}
for (k=i-1;k>=1;k--)
{
for (j=1;j<=8;j++)
{
if (ans[k]/maxnum==0)
{
printf("\0");
}
maxnum/=10;
}
printf("%ld",ans[k]);
maxnum=JINWEI/10;
}
printf("n");
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com