課程名稱︰計算機程式設計
課程性質︰必修
課程教師︰李秀惠
開課系所︰資訊系
考試時間︰2006/01/10 14:00 ~ 18:00
注意事項:上機考,可以帶課本
試題 :
Problem 1 - Comments for Course and Exam in all semester (10 points)
[ Description ]
Please write down your comments for course and exam in .c file.
Problem 2 - Uniform-Invoice (統一發票) Prize Winning (20 points)
[ Description ]
In this problem, writing a program to help people match their
uniform-invoice numbers and calculate how much money they win. Now, the rule
is defined in the following.
1. There is one number for grand prize and three numbers for first prize.
2. Grand prize: NT$200,000,000 for matching all the digits from the grand
prize winning number.
3. First prize: NT$200,000 for matching all the digits from any of the first
prize winning numbers.
4. Second prize: NT$40,000 for matching the last seven digits from any of the
first prize winning numbers.
5. Third prize: NT$10,000 for matching the last six digits from any of the
first prize winning numbers.
6. Fourth prize: NT$4,000 for matching the last five digits from any of the
first prize winning numbers.
7. Fifth prize: NT$1,000 for matching the last four digits from any of the
first prize winning numbers.
8. Sixth prize: NT$200 for matching the last three digits from any of the
first prize winning numbers.
In order to identify uniform-invoice, the user will input the file name
for invoice data. In this file, the first line will be the number for grand
prize and the remaining three lines are the numbers for other prizes. Then
the user inputs the file name containing his/her own uniform-invoice numbers,
one number per line. Please write the program to show each uniform-invoice
number, the associated amount of money he/she wins, and the overall amount.
Data format of "invoice.txt" is a number per line. For example
52552845
53549747
70472082
83366121
Data format of "user-invoice.txt" is also a number per line. For example,
there are five numbers.
56212312
21321747
21386121
32198797
53219082
[ Sample Input / Output ]
Please input uniform-invoice file: invoice.txt
Please input user uniform-invoice file: user-invoice.txt
Grand prize winning number is
52552845
First prize winning numbers are
53549747
70472082
83366121
Result:
56212312 -> 0
21321747 -> 200
21386121 -> 1000
32198797 -> 0
53219082 -> 200
Congratulations! You will get the total amount 1400 dollars.
Problem 3 - Insert/Delete/Replace char in the string (20 points)
[ Description ]
Try to use linked lists to store a string and implement three operations
on the linked lists; these are insert, delete, and replace. Detail prototypes
for each operation are defined as the following. The return value is used to
represent operation works or not, where 0 means opeeration fail and 1 means
operation success.
1. To insert a char after the target char.
int insert(LinkNodePtr *sptr, char target, char new);
2. To delete a char that you meet first in the string.
int delete(LinkNodePtr *sptr, char target);
3. To replace a char that you meet first in the string with a new char.
int replace(LinkNodePtr *sptr, char target, char new);
The data structure definition for link node is defined in the following.
struct linknode
{
char data;
struct linknode *nextnode;
};
typedef struct linknode LinkNode;
typedef LinkNode *LinkNodePtr;
[ Sample Input / Output ]
Please input a string: Ce12aaty
Please choose an operation ( 1 for insert, 2 for delete, 3 for replace,
-1 for quit ): 1
Please input: C r
Result: Cre12aaty
Please choose an operation ( 1 for insert, 2 for delete, 3 for replace,
-1 for quit ): 1
Please input: q r
Result: not found, Cre12aaty
Please choose an operation ( 1 for insert, 2 for delete, 3 for replace,
-1 for quit ): 2
Please input: 1
Result: Cre2aaty
Please choose an operation ( 1 for insert, 2 for delete, 3 for replace,
-1 for quit ): 2
Please input: 3
Result: not found, Cre2aaty
Please choose an operation ( 1 for insert, 2 for delete, 3 for replace,
-1 for quit ): 2
Please input: 2
Result: Creaaty
Please choose an operation ( 1 for insert, 2 for delete, 3 for replace,
-1 for quit ): 2
Please input: a
Result: Creaty
Please choose an operation ( 1 for insert, 2 for delete, 3 for replace,
-1 for quit ): 3
Please input: s t
Result: not found, Creaty
Please choose an operation ( 1 for insert, 2 for delete, 3 for replace,
-1 for quit ): 3
Please input: y e
Result: Create
Please choose an operation ( 1 for insert, 2 for delete, 3 for replace,
-1 for quit ): -1
Problem 4 - Guess Possible Number (20 points)
[ Description ]
In this problem, you have to simulate a game of guess possible number.
We define a 4-digit number ([0-9][0-9][0-9][0-9]), and there is no duplicated
digit in the 4-digit number. Given an anwswer number, 1234, the guessed number
is 1432 and the match code will be 2A2B. The match code (#A#B) is defined that
A means match in the correct digit and B means match in the incorrect digit.
As we know that there are 5040 possible solutions in solution set, you are
suggested to use elimination method to guess next possible number. Steps for
game simulation is defined in the following.
1. By random number generation, we get a 4-digit number as the correct answer
2. Again, by random number generation, we get another 4-digit number as a
guessed number
3. Compare the correct answer with the guessed number to get the corresponding
match code
4. Use the elimination method to reduce the solution set. And then randomly
select a number from the solution set.
5. Repeat step 3 to 4 until get the final correct answer. You have to report
all the guess steps on the screen.
[ Sample Input / Output ]
Guess procedure:
...
Problem 5 - Write the functions of cp_strcasecmp(), cp_stricasecmp(),
cp_strcasencmp(), and cp_stricasencmp() (20 points)
[ Description ]
Your job is to implement some your own string comparison functions for
compare two strings in case sensitive and case insensitive mode. In this
problem, you have to compare the character one by one. You only can use
tolower() function in <ctype.h> to handle string comparison in case
insensitive mode and can't use those comparison functions of the string
handling library, for example, strcmp(), strncmp(), strcasecmp() or
strcasencmp(). We define function prototypes for you in the following:
int cp_strcasecmp(const char *s1, const char *s2);
// case sensitive string comparison
int cp_stricasecmp(const char *s1, const char *s2);
// case insensitive string comparison
int cp_strcasencmp(const char *s1, const char *s2, int len);
// case sensitive string comparison
int cp_stricasencmp(const char *s1, const char *s2, int len);
// case insensitive string comparison
The cp_strcasecmp() and cp_stricasecmp() functions compare the null-terminated
strings s1 and s2 in case sensitive and case insensitive mode respectively.
The cp_strcasencmp() and cp_stricasencmp() compares at most len characters in
case sensitive and case insensitive mode respectively. The above four
functions will return an integer greater tham, equal to, or less than 0,
according as s1 is lexicographically greater than, equal to, or less than s2.
tolower -- upper case to lower case letter conversion
SYNOPSIS
#include <ctype.h>
int tolower(int c);
DESCRIPTION
The tolower() function converts an upper-case letter to the
corresponding lower-case letter.
[ Sample Input / Output ]
Please input first string: abcdefg
Please input second string: abcdEFG
Please input length for string comapre: 4
Case sensitive: abcdefg > abcdEFG
Case insensitive: abcdefg = abcdEFG
Case sensitive on comparing first 4 character: abcdefg = abcdEFG
Case insensitive on comparing first 4 character: abcdefg = abcdEFG
Problem 6 - Sorting Integers (20 points)
[ Description ]
You are asked to get at most 200 integers from command-line arguments
(i.e. main(int argc, char *argv[]) ) and sort them. You can use bubbleSort()
as the sorting function defined on page 274-275 in the textbook. By the way,
you can use atoi() to convert ASCII string to integer.
atoi -- convert ASCII string to integer
SYNOPSIS
#include <stdlib.h>
int atoi(const char *nptr);
DESCRIPTION
The atoi() function converts the initial portion of the string pointed
to by nptr to int representation.
[ Sample Input / Output ]
For example, sortInt.exe is your execution file.
>sortInt.exe 9 68 17 6 35 4 233 2 51
Data items in original order
9 68 17 6 35 4 233 2 51
Data items in ascending order
2 4 6 9 17 35 51 68 233
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.243.45