# | Problem | Pass Rate (passed user / total user) |
---|---|---|
13694 | EE2310_Lec_8_1 |
|
13695 | EE2310_Lec_8_2 |
|
Description
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char suit;
char face;
} card_t;
/*
* face's values are 'A', '2',..., 'T', 'J', 'Q', 'K',
* in which 'T' stands for 10.
* suit's values are 'S', 'H', 'D', 'C'
*/
void input_card_t(card_t *ptr_card1){
/*
Your work here.
*/
}
void output_card_t(card_t *ptr_card1){
/*
Your work here. Output "10" instead of 'T'
*/
}
int main(){
card_t card_arr[10];
for(int i=0; i<10; ++i){
input_card_t(card_arr + i);
}
for(int i=0; i<9; ++i){
output_card_t(card_arr + i);
printf(" ");
}
output_card_t(card_arr + 9);
printf("\n");
return 0;
}
Input
S2 H2 D2 CT S8 HA DJ HK HQ C5
Output
S2 H2 D2 C10 S8 HA DJ HK HQ C5
Sample Input Download
Sample Output Download
Tags
Discuss
Description
#include <stdio.h>
#include <stdlib.h>
#define MAX_NEG -1000000000
typedef struct stack {
int *head;
int top;
int max_size;
} stack_arr_t;
void stack_init(stack_arr_t *s, int size) {
/* your code here
*
*/
}
void stack_destroy(stack_arr_t *s) {
/* your code here
*
*/
}
void push(int elem, stack_arr_t *s) {
/* your code here
*
*/
}
int pop(stack_arr_t *s) {
/* your code here
* if you pop an empty stack, return MAX_NEG;
*/
}
void show_stack(stack_arr_t *s) {
/* your code here
* if the stack is empty, printf("Stack empty!\n");
* otherwise, printf("Stack contains %d element(s)\n", ...);
* and then printf("top = %d, max_size = %d\n",...);
*/
}
/* do not change main() !!! */
int main(){
stack_arr_t my_stack;
int input_size, temp, max_size, pop_size;
/* input stack's max size */
scanf("%d", &max_size);
stack_init(&my_stack, max_size);
/* input elements to be pushed */
scanf("\n%d", &input_size);
int i;
for(i=0; i<input_size; ++i){
scanf("\n%d", &temp);
push(temp, &my_stack);
}
/* input number of elements to be popped */
scanf("\n%d", &pop_size);
for(i=0; i < pop_size-1; ++i){
printf("%d ", pop(&my_stack));
}
if (0 != pop_size){
printf("%d\n", pop(&my_stack));
}
show_stack(&my_stack);
stack_destroy(&my_stack);
return 0;
}
/* in show_stack(), if the stack is empty, printf("Stack empty!\n"); */
Input
6
6
1 2 3 4 5 6
4
Output
6 5 4 3
Stack contains 2 element(s)
1 2
top = 2, max_size = 6