| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10221 | moocHW7a |
|
| 10243 | moocFinal3_Max Pooling |
|
Description
搜尋某個產品名稱
找出符合的產品
並且依照評價高低
從評價高分到低分排序
如果評價相同
則繼續依照價格由低價到高價排序
範例程式:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// #define ONLINE_JUDGE
/*
struct for product items
*/
typedef struct _Product {
char name[51];
float price;
float review;
int num_reviews;
} Product;
int compare(const void *a, const void *b)
{
Product *ia, *ib;
ia = *(Product **)a;
ib = *(Product **)b;
/* your code here */
}
void show_product(Product *item)
{
printf("%s, ", item->name);
printf("$%.2f, ", item->price);
printf("%.1f\n", item->review);
}
int main(void)
{
Product **items;
int i, j;
int ndata, nqueries;
char query[51];
#ifndef ONLINE_JUDGE
freopen("testcase1", "r", stdin);
//freopen("out1", "w", stdout);
#endif
scanf("%d", &ndata);
while (getchar() !='\n');
items = (Product**) malloc(sizeof(Product*) * ndata);
for (i=0; i<ndata; i++) {
items[i] = (Product*) malloc(sizeof(Product));
fgets(items[i]->name, 31, stdin);
items[i]->name[strlen(items[i]->name)-1] = 0;
scanf("%f", &items[i]->price);
scanf("%f", &items[i]->review);
scanf("%d", &items[i]->num_reviews);
while (getchar() !='\n');
}
scanf("%d", &nqueries);
while (getchar() !='\n');
qsort(items, ndata, sizeof(Product *), compare);
for (i=0; i<nqueries; i++) {
/* your code */
}
for (i=0; i<ndata; i++) {
free(items[i]);
}
free(items);
return 0;
}
Input
第一行的數字代表有幾個產品
接著每四行代表一個產品的資訊:
產品名稱
產品價格
產品評價
產品評價數
再來是一個數字,代表有幾筆 query
之後的每一行代表一筆 query
每筆 query 的內容為品牌名稱
Output
根據每筆 query 輸出:
品牌名稱
產品名稱1, 產品價格1, 產品評價1
...
產品名稱N, 產品價格N, 產品評價N
每一個品牌名稱下面可能會接好幾個產品
請依照題目要求將這些產品排序好
Sample Input Download
Sample Output Download
Tags
Discuss
Description
輸入一個 N x N 矩陣,輸出一個新的 (N-2) x (N-2) 矩陣,新的矩陣的每個元素,對應到原來的矩陣 每一個 3 x 3 區塊的範圍內的最大值,例如輸入的矩陣是
10 20 30 90 30
50 60 30 20 50
80 50 70 60 20
90 40 30 20 80
20 30 40 50 90
輸出的矩陣
80 90 90
90 70 80
90 70 90
以輸出矩陣的左上角的 80 為例 因為它是原來輸入的矩陣的左上角 3 x 3 區域內的最大值:
10 20 30
50 60 30
80 50 70
又例如輸出的矩陣的中間的 70,是原本輸入矩陣的正中央 3x3 區塊內的最大值:
60 30 20
50 70 60
40 30 20
Input
第一行是一個整數 N,然後接下來 N 行,每行包含 N 個整數,總共 N*N 個整數。
N 的值最小是 3,最大不超過 10。
Output
N-2 行,每一行包含 N-2 個整數,兩個元素之間有一個空白隔開,每一行最後都要換行。