记录详情

Accepted

/in/foo.cc: In function 'void age(int)':
/in/foo.cc:9:11: warning: iteration 7 invokes undefined behavior [-Waggressive-loop-optimizations]
   agepl[i]=0;
   ~~~~~~~~^~
/in/foo.cc:8:15: note: within this loop
  for(int i=1;i<=8;++i)
              ~^~~
# 状态 耗时 内存占用
#1 Accepted 1ms 220.0 KiB
#2 Accepted 1ms 232.0 KiB
#3 Accepted 1ms 224.0 KiB
#4 Accepted 1ms 232.0 KiB
#5 Accepted 1ms 212.0 KiB

代码

#include<iostream>
using namespace std;

void age(int n)
{
	int agepl[8];
	int a;
	for(int i=1;i<=8;++i)
		agepl[i]=0;
	for(int i=1;i<=n;++i)
	{
		cin>>a;
		if(a<=0)
			agepl[1]++;
		else if(a>150)
			agepl[7]++;
		else if(a>0&&a<=30)
			agepl[2]++;
		else if(a>30&&a<=60)
			agepl[3]++;
		else if(a>60&&a<=90)
			agepl[4]++;
		else if(a>90&&a<=120)
			agepl[5]++;
		else if(a>120&&a<=1500)
			agepl[6]++;
	}
	for(int i=1;i<=7;++i)
		cout<<agepl[i]<<endl;
}

int main()
{
	int n;
	cin>>n;
	age(n);
	return 0;
}

信息

递交者
类型
递交
题目
P1012 统计年龄
语言
C++
递交时间
2019-07-29 16:27:12
评测时间
2019-07-29 16:27:12
评测机
分数
50
总耗时
6ms
峰值内存
232.0 KiB