作业若干

      逝水华年 2005-9-13 22:56
Problem Set
Here is the problem set. The number of stars indicates the difficulty level of the problem. The more number of stars a problem has, the more difficult it is.
[101] A+B Problem ★
Calculate a + b
Input
a and b
Output
a+b
Sample Input (input.txt)
1 5
100 200
Sample Output(output.txt)
6
300
Hint
Use + operator

[102] Sum★★
Your task is to find the sum of all integer numbers lying between 1 and N inclusive.
Input
The input consists of several lines, each line contains a single integer N that is not greater than 1000 by it's absolute value.
Output
For each integer in input file, write to the output file a single integer number that is the sum of all integer numbers lying between 1 and N inclusive.
Sample Input
-3
100
1
Sample Output
-5
5050
1
[103] Delete blanks★★★
Remove the redundant blanks in a string. If there is only one blank, keep it, if there are several continuous blanks, then remove redundant ones and reserve one. If there is any blank at the end of the line, remove them all. The length of all the string will not exceed 256.
Input
A string
Output
A string with the redundant blanks deleted
Sample Input (notice that there are serveral blanks at the end of the line)
I am a student!
Sample Output
I am a student!
[104] Substring★★
Get a substring from a string. The length of all the string will not exceed 256.
Input
Line 1: A string from which you want to get a substring.
Line 2: An integer indicating the start position of the substring.
Line 3: The length of the substring you want go get.
Output
The substring
Sample Input
I am a student
3
4
Sample Output
am a
[105] Replace String★★
Replace a string with another string from a certain position. The length of all the string will not exceed 256.
Input
Line 1: The destination string which will be replaced
Line 2: The source string you want to replace with
Line 3: An integer indicating the start position in the destination string, you replace the destination string from the start position to the end with the source string.
Output
A string represents the destination string that has been replaced.
Sample Input
I am a boy
teacher
8
Sample Output
I am a teacher
[106] String Match★★★
If the first string includes the second string, return the start position of the substring occurred in the first string with the cases ignored, otherwise return 0. The length of all the string will not exceed 256.
Input
Line 1: A destination string to be matched
Line 2: The substring to be matched with
Output
Integers indicating the start position of the all the occurrence of the substring in the destination string and separated by a single space
Sample Input
The C Language is the most beautiful computer language.
the
Sample Output
0 18
[107] Judge Power ★★★
Judge whether an integer has the power of 2.
Input
A set of integers, each one occupies a line.
Output
A set of Yes of No indicating whether the corresponding integer has the power of 2
Sample Input
2
8
34
1024
56
Sample Output
Yes
Yes
No
Yes
No
[108] Reverse ★★
Reverse a list of integers. The number of integers in a list will never exceed 100.
Input
A list of integers separated by a comma
Output
A list of integers separated by a comma which has the reversed order of the input list
Sample Input
45,89,4,3,56
Sample Output
56,3,4,89,45

[109] Integer Sorting ★★
Sort a list of integers. The number of integers in a list will never exceed 100.
Input
Line 1: A list of integers separated by a comma
Line 2: An integer indicating the order you have to sort the integers. 1 means ascendant, while 0 descendant.
Output
All the integers sorted with the specified order
Sample Input
45,89,4,3,56
1
Sample Output
3,4,45,56,89
[110] Combine and Sort ★★★
Combine two lists of integers in a specified order. The number of integers in a list will never exceed 100.
Input
Line 1: Two integers N and M separated by a space which represents the number of integers in the following two lines
Line 2: The first list of integers separated by a comma
Line 3: The second list of integers separated by a comma
Line 4: An integer indicating the order you have to sort the integers; 1 means ascendant, while 0 descendant
Output
All the integers of the two lists sorted with the specified order separated by a comma
Sample Input
5 4
45,89,4,3,56
1,2,5,7
1
Sample Output
1,2,3,4,7,45,56,89
[111] Matrix Multiply ★★
Multiply two 3 X 3 matrixes, output the result matrix which is also a 3 X 3 matrix.
Input
Line 1~3: matrix one
Line 4~6: matrix two
Output
The matrix which is the multiple of matrix one and two
Sample Input
1, 1, 1
1, 3, 1
1, 1, 9
1, 1, 2
1, 3, 1
2, 1, 1
Sample Output
4, 5, 4
6,11,6
20, 13, 12

[112] Figures Description ★★
Convert a decimal integer to its text description format. The integer will not exceed 999,999,999,999.
Input
A decimal
Output
Text description of the decimal
Sample Input
1960
Sample Output
One thousand nine hundred and sixty

[113] Record Sorting ★★★★
There is a group of student records; each record consists of a student name, gender, major, English score, Japanese score and Computer score. Your task is to sort all these records according to certain column in ascendant or descendant order. If two values are the same, output the records in the order of their appearance sequence in the input file.
Input
Line 1: The first integer N represents the number of the following records. (N <= 100). The second integer indicates which column you are asked to sort (1 means the name column, 2 means gender column and so on). The last integer shows in which order the records are sorted (1 means ascendant, while 0 descendant).
Line 2~(N+1): N lines; each line represents a student record. Notice that each element in a record is separated by a tab (‘\t’).
Output
N lines of records which have been sorted in a specified order.
Sample Input
4 3 0
Alice    Female    89    90.5    65
Mary    Female    65    80    46
Edward    Male    98    97    61
Nick    Male    65    62.5    99.5
Sample Output
Edward    Male    98    97    61
Alice    Female    89    90.5    65
Mary    Female    65    80    46
Nick    Male    65    62.5    99.5
Hint
Use structure to store a record.
Use strcmp function to compare two strings.
Notice that the scores can be float and also notice the format of scores.

[114] Base Conversion ★★★
Convert a decimal integer to another base data type. The octal number begins with a ‘0’, and the hexadecimal number begins with ‘0x’. For example ‘017’ is 15 in decimal, and ‘0x1F’ is 31 in decimal.
Input
Line 1: The first integer N represents the number of the following lines. (N <= 100).
Line 2~(N+1): N lines; each line consists of a decimal and a character. The character indicates to which base type you are asked to convert the decimal. ‘B’ means binary, ‘H’ means hexadecimal and ‘O’ means oxtal.
Output
N lines, each line represents the converted number.
Sample Input
3
5 B
31 H
7 O
Sample Output
101
0x1F
07
[115] Expression Calculator ★★★
Implement an algorithm expression calculator. The expression contains only nonnegative integers, parentheses (‘(’, ‘)’) and operators (‘+’, ‘-’, ‘*’, ‘/’)
Input
Line 1: The first integer N represents the number of the following lines. (N <= 100).
Line 2~(N+1): N lines; each line represents an algorithm expression
Output
N lines, each line represents the result of each expression
Sample Input
3
5+6
(4+8*2) – 12/4
5*(4+5)-5*(10-2*4)
Sample Output
11
17
35
Hint
Use two stacks to hold operators and operands respectively.



标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}