#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct Array
{
int* pa;
short ilen;
short stu;
};
void main()
{
struct Array a={NULL,0,-1};
int Q,i;
while(1)
{
printf("Please input[1/2/3/0]:");
scanf("%d",&Q);
switch(Q)
{
case 0:
{
free(a.pa);
a.pa=NULL;
a.ilen=0;
a.stu=-1;
printf("get over!\n");
return ;
}
case 1:
{
int grade;
printf("请输入成绩:");
scanf("%d",&grade);
if(a.stu+1==a.ilen)
{
int* anew=(int*)malloc((a.ilen+5)*4);
if(anew!=NULL)
{
memcpy(anew,a.pa,a.ilen*4);
a.ilen+=5;
free(a.pa);
a.pa=anew;
}
}
a.pa[++a.stu]=grade;
}break;
case 2:
{
for(i=0;i<=a.stu;i++)
printf("%d\n",a.pa[i]);
}break;
case 3:
{
int T;
printf("请输入查找的成绩:");
scanf("%d",&T);
for(i=0;i<=a.stu;i++)
if(T==a.pa[i])
printf("%d\n",a.pa[i]);
}break;
default:
printf("系统错误\n");
}
}
}