杭电ACM2023为什么wa啊,
写的可能比较乱,帮忙看下#include<stdio.h>#include<malloc.h>intmain(void){intn,m,i,j,t,x;double**a...
写的可能比较乱,帮忙看下
# include <stdio.h>
# include <malloc.h>
int main(void)
{
int n,m,i,j,t,x;
double ** a;
double s;
double k[5];
while(scanf("%d%d",&n,&m) != EOF)
{
a = (double **)malloc(sizeof(double *)*n);
for(i = 0;i < n;i ++)
a[i] = (double *)malloc(sizeof(double)*m);
for(i = 0;i < n;i ++)
for(j = 0;j < m;j ++)
scanf("%lf",&a[i][j]);
for(i = 0;i < n;i ++)
{
for(j = 0,s = 0;j < m;j ++)
s+=a[i][j];
s = s / m;
i!=n-1?printf("%.2f ",s):printf("%.2f\n",s); //学生平均成绩
}
for(j = 0;j < m;j ++)
{
for(i = 0,k[j] = 0;i < n;i ++)
k[j] += a[i][j];
k[j] = k[j]/n;
j!=m-1?printf("%.2f ",k[j]):printf("%.2f\n",k[j]);
}
for(i = 0,x = 0;i < n;i ++)
{
for(j = 0,t = 0;j < m;j ++)
{
if(a[i][j] > k[j])
t ++;
if(t == m) x++;
}
}
printf("%d\n\n",x);
for(i = 0;i < n;i ++)
free(a[i]);
}
return 0;
} 展开
# include <stdio.h>
# include <malloc.h>
int main(void)
{
int n,m,i,j,t,x;
double ** a;
double s;
double k[5];
while(scanf("%d%d",&n,&m) != EOF)
{
a = (double **)malloc(sizeof(double *)*n);
for(i = 0;i < n;i ++)
a[i] = (double *)malloc(sizeof(double)*m);
for(i = 0;i < n;i ++)
for(j = 0;j < m;j ++)
scanf("%lf",&a[i][j]);
for(i = 0;i < n;i ++)
{
for(j = 0,s = 0;j < m;j ++)
s+=a[i][j];
s = s / m;
i!=n-1?printf("%.2f ",s):printf("%.2f\n",s); //学生平均成绩
}
for(j = 0;j < m;j ++)
{
for(i = 0,k[j] = 0;i < n;i ++)
k[j] += a[i][j];
k[j] = k[j]/n;
j!=m-1?printf("%.2f ",k[j]):printf("%.2f\n",k[j]);
}
for(i = 0,x = 0;i < n;i ++)
{
for(j = 0,t = 0;j < m;j ++)
{
if(a[i][j] > k[j])
t ++;
if(t == m) x++;
}
}
printf("%d\n\n",x);
for(i = 0;i < n;i ++)
free(a[i]);
}
return 0;
} 展开
1个回答
2011-11-29
展开全部
#include<肢芦喊iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main(void)
{
int n,m;
int array[51][6];
int student[51];
int course[6];
while(cin>>n>>m)
{
memset(array,0,sizeof(array));
memset(student,0,sizeof(student));
memset(course,0,sizeof(course));
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
cin>>历野array[i][j];
student[i]+=array[i][j];
course[j]+=array[i][j];
}
}
for(int i=1; i<=n; i++)
{
printf("%.2lf%c",1.0*student[i]/m,i<n?' ':'\n');
}
for(int j=1; j<=m; j++)
{
printf("%.2lf%c",1.0*course[j]/n,j<m?' ':'\n');
}
int count=0;
for(int i=1; i<=n; i++)
{
bool state=true;
for(int j=1; j<=m; j++)
{
if(array[i][j]<1.0*course[j]/n)
{
state=false;
break;
}
}
if(state)
{
count++;
}
}
cout<<count<<endl<<endl;
}
return 0;
}
自己看看吧哗盯。。
#include<cstring>
#include<cstdio>
using namespace std;
int main(void)
{
int n,m;
int array[51][6];
int student[51];
int course[6];
while(cin>>n>>m)
{
memset(array,0,sizeof(array));
memset(student,0,sizeof(student));
memset(course,0,sizeof(course));
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
cin>>历野array[i][j];
student[i]+=array[i][j];
course[j]+=array[i][j];
}
}
for(int i=1; i<=n; i++)
{
printf("%.2lf%c",1.0*student[i]/m,i<n?' ':'\n');
}
for(int j=1; j<=m; j++)
{
printf("%.2lf%c",1.0*course[j]/n,j<m?' ':'\n');
}
int count=0;
for(int i=1; i<=n; i++)
{
bool state=true;
for(int j=1; j<=m; j++)
{
if(array[i][j]<1.0*course[j]/n)
{
state=false;
break;
}
}
if(state)
{
count++;
}
}
cout<<count<<endl<<endl;
}
return 0;
}
自己看看吧哗盯。。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询