# | Problem | Pass Rate (passed user / total user) |
---|---|---|
11490 | The Cat Society |
|
12568 | Reverse Linked List ver 2 |
|
13099 | Wish List |
|
13572 | String Operations 1 |
|
14537 | My String |
|
Description
Wild cats take care of each other in the wild. However, when winter comes, the preys are not enough to feed all the cats. Therefore, the cats dine according to the order of their occupations. The order is as follows:
1. elder
2. nursy
3. kitty
4. warrior
5. apprentice
6. medicent
7. deputy
8. leader
In the tradition of the cat society, three different cats serve as the medicent, the deputy, and the leader respectively.
As for the other cats, except that the apprentices have the dining priority of the young over the old, for the other occupations, the old have higher priority. If the occupations and the ages of two or more cats are the same, they will dine in lexicographic order according to their names.
Input
There are multiple test cases.
The first line of each test case contains two integers N and M, indicating the number of cats and the portions of food respectively, where 0<N,M<=10000.
The next N lines are the information of each cat, including name, occupation, and age.
The length of the names will not exceed 30 letters and will contain no spaces.
Output
Please output the cats that could eat the food in order, each name a line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given several operations, push x
, pop
, print
, reverse
, create a linked list dynamicly.
- push x: Add one Node (with data = x) at the front of linked list.
- pop: Delete the Node at the front of linked list.
- reverse: reverse the current linked list
- print: output the linked list in given format.
You have to implement 3 functions:
1. void Push(Node** ptr_head,int x)
2. void Pop(Node** ptr_head)
3. void Reverse_List(Node** ptr_head)
Note: Modify the Node* head
by Node** ptr_head
Input
There’re operations on several lines.
All operations are one of push x
, pop
, print
, reverse
.
It’s guaranteed that:
- Number of operations is less than 5,000,000
- Integer x is in [−1000,1000]
- The maximum length of linked list is less than 10,000.
Output
Output the linked list for every print
.
Sample Input Download
Sample Output Download
Partial Judge Code
12568.cPartial Judge Header
12568.hTags
Discuss
Description
During the New Year sale, Panda wants to purchase items from his wish list.
The wish list has N items.
Each item has name, original price, discount, quality (Si, Pi, Di, Qi).
The selling price for an item is its original price subtract discount (Pi − Di)
Panda’s budget is only X dollars which is too less to pruchase all items in wish list.
He designs 3 kinds of purchase strategies for items:
Strategy 1: less selling price first, the item with less selling price will be selected first.
Strategy 2: more discount first, the item with more discount will be selected first.
Strategy 3: higher quality first, the item with higher quality will be selected first.
Panda will sort the wish list by applying these strategies in a special order O.
Then purchase the items from top to down until his budget can’t buy anything.
This problem is a partial judge problem.
You have to complete functions under given interface.
Please refer to function.h
, main.c
for implementation details.
function.h
#ifndef __FUNCTION_H__
#define __FUNCTION_H__
typedef struct _Item {
char* name;
int price;
int discount;
int quality;
} Item;
Item* CreateList(int N);
void AddItem( Item* L, int idx, char* name, int price, int discount, int quality );
void DeleteList(Item* L, int N);
int price_cmp( const void* lhs, const void* rhs );
int discount_cmp( const void* lhs, const void* rhs );
int quality_cmp( const void* lhs, const void* rhs );
#endif
main.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "function.h"
#define MAX_NAME 100
typedef int (*func_ptr)(const void*, const void*);
int N, X;
int O[3];
func_ptr cmp[3] = { price_cmp, discount_cmp, quality_cmp };
int qsort_cmp( const void* lhs, const void* rhs){
for(int i=0; i<3; i++){
int res = cmp[ O[i]-1 ](lhs, rhs);
if( res != 0 ) // If not same
return res;
}
// This case will not appear in Test cases;
int str_res = strcmp( ((Item*)lhs)->name, ((Item*)rhs)->name);
if( str_res < 0 ) return -1;
if( str_res > 0 ) return 1;
return 0;
}
int main(){
int T;
scanf("%d", &T);
for(int cnt=1; cnt<=T; cnt++){
scanf("%d %d %1d%1d%1d", &N, &X, &O[0], &O[1], &O[2]);
Item* L = CreateList(N);
char name[MAX_NAME+1];
int P, D, Q;
for(int i=0; i<N; i++){
scanf("%s %d %d %d", name, &P, &D, &Q);
AddItem(L, i, name, P, D, Q);
}
qsort( L, N, sizeof( Item ), qsort_cmp);
printf("case %d:\n", cnt);
for(int i=0; i<N; i++){
int sp = L[i].price - L[i].discount;
if( sp < X ){
printf("%s\n", L[i].name);
X -= sp;
}
}
DeleteList(L, N);
}
return 0;
}
Input
This problem contains multiple inputs.
There’s an integer T on the first line, denoting the number of input.
For each input, there’re N, X, O on the first line.
There’re Si, Pi, Di, Qi on the following N lines.
It’s guaranteed that:
- 1 ≤ T ≤500
- 1 ≤ N ≤ 1000
- 1 ≤ X ≤106
- |Si| ≤ 100
- (Pi, Di, Qi) ≠ (Pj, Dj, Qj) for all i ≠ j.
- O ∈{123, 132, 213, 231, 312, 321 }
Output
Output the item names Panda decides to purchase ( in sorted wish list order ).
Explaintation for Sample I/O:
The budget is 200, and the wish list:
A 120 50 1 // selling price = 70
B 100 40 2 // selling price = 60
C 100 30 2 // selling price = 70
D 100 40 3 // selling price = 60
E 100 30 4 // selling price = 70
- O = 123:
- First, sort by selling price (increasing order)
- Second, sort by discount (decreasing order) for those have the same selling price.
- Third, sort by quality (decreasing order) for those have the same selling price and discount.
- The sorted list:
D 100 40 3 B 100 40 2 A 120 50 1 E 100 30 4 C 100 30 2
- Pandas will using 190 dollars to purchase “D”, “B”, “A”
- O = 312:
- First, sort by quality
- Second, sort by selling price for those have the same quality.
- Third, sort by discount for those have the same selling quality and selling price.
- The sorted list:
E 100 30 4 D 100 40 3 B 100 40 2 C 100 30 2 A 120 50 1
- Pandas will using 190 dollars to purchase “E”, “D”, “B”
Sample Input Download
Sample Output Download
Partial Judge Code
13099.cPartial Judge Header
13099.hTags
Discuss
Description
Input
The first line contains a string s, which consists of only lowercase Latin characters. The second line contains a integer Q. The next Q lines, each contains two characters A and B.
Constraints
- 1≤|s|≤106
- 1≤Q≤105
- A,B∈[a−z]
for testcases 1~3, 1≤|s|≤1000.
for testcases 4~6, there’s no additional constraints.
Output
Print the resulting string in one line after applying the Q operations.
(remember to print a new line character)
Sample Input Download
Sample Output Download
Tags
Discuss
Description
There are interesting string operations there.
- a + b: Concatenate the string b after the string a.
- a - b: If string b has appeared in string a, delete the first appearance of b in a, otherwise output "error".
- a . b: Treat it as a floating-point number and round to six decimal places. If there are fewer than six decimal places, append '0' until reaching six decimal places.
- a @ b1_b2_b3_...bk: For all strings bi concatenated with '_', if a has appeared in string bi, add bi to a list, output the list in this order:
- If |x| > |y|: x is listed before y
- If |x| = |y|: follows the lexicographical order
Input
The first line contains an integer T, representing the number of string operations.
The following T lines each contain a string Si , representing the string operation in the i-th round.
Subtasks
- Testcases 1 ~ 2: 1 ≤ T ≤ 1000, 1 ≤ |S | ≤ 104, only "+" operation, a and b are guaranteed to consist of lowercase letters
- Testcases 3 ~ 4: 1 ≤ T ≤ 1000, 1 ≤ |S | ≤ 104, "+, -" operations, a and b are guaranteed to consist of lowercase letters
- Testcases 5 ~ 6: 1 ≤ T ≤ 1000, 1 ≤ |S | ≤ 104, "+, -, ." operations, a and b are guaranteed to consist of lowercase letters and digits
- Testcases 7 ~ 8: 1 ≤ T ≤ 1000, 1 ≤ |S | ≤ 5*104, only "@" operation, a and b are guaranteed to consist of lowercase letters and "_"
Output
Output T lines, each containing a string Si after operation.
Please remember to print "\n" at the end.
Aftermath, a student in NTHU, is very good at programming. Today, as usual, she comes up with a programming problem but felt bored to solve it by herself(it’s too easy for her!). Thus, she left the problem to you, that is:
Given a string that consists of only lowercase Latin characters, there are Q operations to apply on this string. Each operation is represented by two characters, let’s say A and B, and you have to turn every A in the given string to B. After the Q operations, you should print the resulting string in one line(remember to print a new line character).