算法笔记3.2-A题-查找元素
题目链接
#include
int score[1005];
int main(void)
{
int N, find;
while(scanf("%d", &N) != EOF && N)
{
for(int i = 0; i < N; i++)
scanf("%d", &score[i]);
scanf("%d", &find);
int cnt = 0;
for(int j = 0; j < N; j++)
if(find == score[j]) cnt++;
printf("%d\n", cnt);
}
return 0;
}
算法笔记3.2-B题-找x
题目链接
#include
int num[205];
int main(void)
{
int n, x, sub;
while(scanf("%d", &n) != EOF)
{
for(sub = 0; sub < n; sub++)
scanf("%d", &num[sub]);
scanf("%d", &x);
for(sub = 0; sub < n; sub++)
if(x == num[sub]) {printf("%d\n", sub); break;}
if(sub == n) printf("-1\n");
}
return 0;
}
算法笔记3.2-C题-查找学生信息
题目链接
#include
#include
struct student
{
char number[10];
char name[100];
char gender[10];
int age;
}msg[2000];
int main(void)
{
int N, M;
while(scanf("%d", &N) != EOF)
{
for(int i = 0; i < N; i++)
scanf("%s %s %s %d", msg[i].number, msg[i].name, msg[i].gender, &msg[i].age);
scanf("%d", &M);
while(M--)
{
char num[10];
int exsist = 0;
scanf("%s", num);
for(int j = 0; j < N; j++)
{
if(!strcmp(num, msg[j].number))
{
exsist = 1;
printf("%s %s %s %d\n", msg[j].number, msg[j].name, msg[j].gender, msg[j].age);
break;
}
}
if(!exsist) printf("No Answer!\n");
}
}
return 0;
}
算法笔记3.2-D题-查找
题目链接
#include
int a[105];
int main(void)
{
int n, m, find;
while(scanf("%d", &n) != EOF)
{
for(int i = 0; i < n; i++)
scanf("%d", &a[i]);
scanf("%d", &m);
while(m--)
{
scanf("%d", &find);
int j;
for(j = 0; j < n; j++)
if(find == a[j]) {printf("YES\n"); break;}
if(j == n) printf("NO\n");
}
}
return 0;
}
算法笔记3.2-E题-学生查询
题目链接
#include
struct student
{
int num;
char name[100];
char gender[100];
int age;
}msg[500];
int main(void)
{
int n, m;
while(scanf("%d", &m) != EOF)
{
while(m--)
{
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%d %s %s %d", &msg[i].num, msg[i].name, msg[i].gender, &msg[i].age);
int find, j;
scanf("%d", &find);
for(j = 0; j < n; j++)
if(find == msg[j].num) {printf("%d %s %s %d\n", msg[j].num, msg[j].name, msg[j].gender, msg[j].age); break;}
}
}
return 0;
}