# Xiamen University C language computer 1493 data search

1493. Data search

Time limit: 1000 MS memory limit: 65536 K

Number of submissions: 1 (0 users) number of passes: 1 (1 users)

Problem description
Query "item No. inventory price volume" of n goods data according to certain conditions, and now find the data greater than or equal to a certain value according to one of the conditions (query 1 by inventory, query 2 by price, query 3 by volume). Output qualified data information.

Input format
The first line of input is an integer N, representing N goods data. (N<=1000)
Next, enter the item no., inventory, price and volume in each line, where the item No. is a six digit integer and the rest data is an integer in the range [010000].
Enter two query integers K ∈ {1,2,3}, which means to search according to the k-th condition. As mentioned in the title, 0 < = s < = 10000 means to search for data greater than or equal to the value.

Output format
Output qualified goods data (including goods number, inventory, price and volume) in the original order; if there is no qualified data, output "nothing".

sample input
3
122034  70 50 30
230201  50 60 70
102203  56 90 63
2 60

sample output
230201  50 60 70
102203  56 90 63

source

xmu

```#include <stdio.h>
#include <stdlib.h>

struct Good
{
int id;
int stock;
int price;
int volume;
};

void search_by_stock(struct Good *list, int n, int query)
{
int i, found = 0;
for (i = 0; i < n; ++i)
{
if (list[i].stock >= query)
{
found = 1;
printf("%06d %d %d %d\n", list[i].id, list[i].stock, list[i].price, list[i].volume);
}
}
if (!found)
printf("nothing\n");
}

void search_by_price(struct Good *list, int n, int query)
{
int i, found = 0;
for (i = 0; i < n; ++i)
{
if (list[i].price >= query)
{
found = 1;
printf("%06d %d %d %d\n", list[i].id, list[i].stock, list[i].price, list[i].volume);
}
}
if (!found)
printf("nothing\n");
}

void search_by_volume(struct Good *list, int n, int query)
{
int i, found = 0;
for (i = 0; i < n; ++i)
{
if (list[i].volume >= query)
{
found = 1;
printf("%06d %d %d %d\n", list[i].id, list[i].stock, list[i].price, list[i].volume);
}
}
if (!found)
printf("nothing\n");
}

int main()
{
int n, k, s, i;
struct Good list[1005];

scanf("%d", &n);
for (i = 0; i < n; ++i)
scanf("%d %d %d %d", &list[i].id, &list[i].stock, &list[i].price, &list[i].volume);
scanf("%d %d", &k, &s);
if (k == 1)
search_by_stock(list, n, s);
else if (k == 2)
search_by_price(list, n, s);
else
search_by_volume(list, n, s);

return 0;
}
```

Tags: REST

Posted on Sun, 03 May 2020 08:44:04 -0400 by dougal85