ps:多组输入的方法
while(scanf("%d %d ",&n,&m)!= EOF){}
详细可参考下C语言中实现多组数据输入输出_weixin_45096811的博客-CSDN博客
#include<stdio.h>
int main()
{
int i, n, m, j,k;
int a[10020], b[10020], c[20040];
while (scanf("%d %d ", &n, &m) != EOF)
//while(n>0)
{
for (i = 0; i < n; i++)
{
scanf("%d ", &a[i]);
}
for (j = 0; j < m; j++)
{
scanf("%d ", &b[j]);
}
i = 0;
j = 0;
k = 0;
while ((i <= n - 1) && (j <= m - 1))
{
if (a[i] <= b[j])
{
c[k] = a[i];
i++;
k++;
}
else
{
c[k] = b[j];
j++;
k++;
}
while (i <= n - 1)
c[k++] = a[i++];
while (j <= m - 1)
c[k++] = b[j++];
for (k = 0; k < m + n; k++)
printf("%d ", c[k]);
printf("\n");
}
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct stu
{
char name[20];
int score;
}s1[100];
int main()
{
int i=0,j,k=0;
int cnt = 0;
int count = 0;
int a[100];
char p[10] = { 0 };
char Name[20];
while (1)
{
scanf("%s", p);
if (strcmp(p, "end") == 0)
{
break;
}
if (strcmp(p, "insert") == 0)
{
scanf("%s %d", s1[cnt].name, &s1[cnt].score);
cnt++;//表示已有的人数
//continue;
}
if (strcmp(p,"find") == 0)
{
count = 0;//假设未找到
scanf("%s",Name);
for (j = 0; j < cnt ; j++)
{
if (strcmp(s1[j].name, Name) == 0)
{
a[k] = j;
k++;
count = 1;//找到了
break;
}
}
}
}
for (i = 0; i < k; i++)
{
printf("%d\n", s1[a[i]].score);
}
if (count == 0)
{
printf("-1\n");
}
return 0;
}