这道题不知道为什么WA,最后换了printf函数输出就AC了。。。醉了
#include
#include
using namespace std;
void prt(double *a,int n)
{
for(int i = 0;i != n - 1;i ++)
{
printf("%.2lf ",a[i]);
}
printf("%.2lf\n",a[n-1]);
}
int main()
{
int n,m;
while(cin >> n >> m)
{
int ** array = new int *[n];
for (int i = 0;i != n;i ++)
{
array[i] = new int [m];
for (int j = 0;j != m;j ++)
{
cin >> array[i][j];
}
}
double * studentave = new double[n];
double * classave = new double[m];
double ave1;
for (int i = 0;i != n;i ++)
{
ave1 = 0;
for (int j = 0;j != m;j ++)
{
ave1 += array[i][j];
}
ave1 = ave1/m;
studentave[i] = ave1;
}
double ave2;
for (int j = 0;j != m;j ++)
{
ave2 = 0;
for (int i = 0;i != n;i ++)
{
ave2 += array[i][j];
}
ave2 = ave2/n;
classave[j] = ave2;
}
int cnt = 0;
int sig;
for(int i = 0;i != n;i ++)
{
sig = true;
for(int j = 0;j != m;j ++)
{
if(array[i][j] < classave[j])
{sig = false; break;}
}
if (sig) cnt ++;
}
prt(studentave,n);
prt(classave,m);
cout << cnt << endl << endl;
delete[] studentave;
delete[] classave;
for (int i = 0;i != n;i ++)
{
delete[] array[i];
}
delete[] array;
}
}
以上为WA的代码
#include以上为AC的代码,不懂为什么cout输出就WA了...#include using namespace std; void prt(double *a,int n) { for(int i = 0;i != n - 1;i ++) { printf("%.2lf ",a[i]); } printf("%.2lf\n",a[n-1]); } int main() { int n,m; while(cin >> n >> m) { int ** array = new int *[n]; for (int i = 0;i != n;i ++) { array[i] = new int [m]; for (int j = 0;j != m;j ++) { cin >> array[i][j]; } } double * studentave = new double[n]; double * classave = new double[m]; double ave1; for (int i = 0;i != n;i ++) { ave1 = 0; for (int j = 0;j != m;j ++) { ave1 += array[i][j]; } ave1 = ave1/m; studentave[i] = ave1; } double ave2; for (int j = 0;j != m;j ++) { ave2 = 0; for (int i = 0;i != n;i ++) { ave2 += array[i][j]; } ave2 = ave2/n; classave[j] = ave2; } int cnt = 0; int sig; for(int i = 0;i != n;i ++) { sig = true; for(int j = 0;j != m;j ++) { if(array[i][j] < classave[j]) {sig = false; break;} } if (sig) cnt ++; } prt(studentave,n); prt(classave,m); cout << cnt << endl << endl; delete[] studentave; delete[] classave; for (int i = 0;i != n;i ++) { delete[] array[i]; } delete[] array; } }