FantasticG
根本不慌
2019-03-11 17:02

求大佬帮忙看看PAT 乙1012

PAT乙1012
求大佬帮忙看一下,为何第7个测试点一直说我段错误?
#include
#include
#include
using namespace std;
int main()
{
int a[50] = {0}, i = 0, a1[5] = { 0 }, count = 0, n1 = 0, n2 = 0;
double count2;
cin >> n2;
for (int i = 0; i < n2; i++)
{
cin >> a[i];
}
for (int n = 0; n < n2; n++)
{
if (a[n] % 5 == 0 && a[n] % 2 == 0)
a1[0] = a1[0] + a[n];
else if (a[n] % 5 == 1)
{
++n1;
if ((n1) % 2 == 1)
a1[1] = a1[1] + a[n];
else a1[1] = a1[1] - a[n];
}
else if (a[n] % 5 == 2)
a1[2] += 1;
else if (a[n] % 5 == 3)
{
a1[3] = a1[3] + a[n];
count++;
}
else if (a[n] % 5 == 4)
if (a1[4] < a[n])
a1[4] = a[n];
}
count2 = ((double)a1[3]) / count;
for (int i = 0; i < 5; i++)
{
if (i == 3)
{
if (a1[i] == 0)
{
cout << "N"<<" ";
continue;
}
printf("%.1f ",count2);
continue;
}
if (i==1&&a1[1] == 0 && n1 != 0)
{
cout << "0 ";
continue;
}
if (a1[i] == 0)
cout << "N";
else cout << a1[i];
if (i != 4)
cout << " ";
}
system("pause");
}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

相关推荐