其他分享
首页 > 其他分享> > CSCI 151

CSCI 151

作者:互联网


CSCI 151: Programming for Scientists and Engineers
Programming Assignment I
Deadline: 26 February 2021, 8:00pm
1. In this task, you are required to write a program that evaluates the scores of two players
in the Tic-Tac-Toe game, .
Your program will perform the following steps:
a. Read an input file “in.txt” which contains the marks, X and O, of the Tic-Tac-Toe
game, which has been played on a table of size KxK. The file has the following
format:
K
X and O marks of the table in row-by-row
For example, if the game is played on a 3x3 table (K=3), then the “in.txt” may
contain the following lines:
b. Count how many of 3 Xs appear consequently in a row, column, or diagonal. Let
this number be score1. In the first example above, score1 is 1 (3 Xs appear in
the diagonal) and in the second example, score1 is 3 (1 in the first column, 2 in
the diagonal).
c. Count how many of 3 Os appear consequently in a row, column, or diagonal. Let
this number be score2. In the first example above, score2 is 0 and in the second
example, score2 is 4 (1 in the last row, 2 in the diagonal and 1 in the smaller
diagonal that starts from the right corner, 2 row). Please look at the picture below:
OOXX OOXX OOXX OOXX
XOXO XOXO XOXO XOXO
XXOX XXOX XXOX XXOX
XOOO XOOO XOOO XOOO
d. Print both scores (score1 and score2) on screen.
2. Write a program that asks the user to enter some text (sentence) and two words (word1
and word2). Then replace each word1 that appears in the sentence with word2. For
example, if the sentence=“aa bb cc dd bb ff abb”, word1=“bb”,
word2=“@@”, then the program should print “aa @@ cc dd @@ ff a@@”. Note:
The only string function you can use in this task is strlen. The code would be case
insensitive. So, the same output would be received if word1=“BB” in the previous
example.
3. Write a program that checks if a number consisting of n digits is a palindrome, and that
the sequence of the first ceil(n/2) digits of the number is increasing. To recall, an
integer is a palindrome if the reverse of that number is equal to the original number. For
example, if the number is 12321, then that number is a palindrome, and, in addition, the
sequence {123} is increasing. If the number is 13231, then that number is a palindrome,
but the sequence {132} is non-increasing. Finally, if the number is 1323, then that
number is neither a palindrome, nor the required sequence is increasing. Note: ceil(x) is
the ceiling function. Your program should perform the following steps:
a. Ask the user to enter an integer.
b. Determine the number of digits and store the value as n.
c. Determine the reverse form of that integer.
d. Compare if the original and the reverse form are equal. If they are, then go to e. If
they are not, then go to f.代做CSCI 151程序
e. Compare if the sequence of the first ceil(n/2) digits of the number is increasing.
f. Output the statement whether an integer is a palindrome and whether it satisfies
the required condition.
4. Write a program that will ask the user to enter 3 integers: a, b, and c; sort them in
ascending order, and print the three values a, b, and c times, accordingly; with every
number on a new line. If the entered numbers are repeated, use the repeated number
once. If the numbers are less than or equal to 0, then they should not be used in the
printed output.
For example, if the three integers are: 5, 2, and 3. Then, the output should be the
following:
Or, if the three integers are: 4, 4, and 7. Then, the output should be the following:
Rules:
● Late submissions will NOT be accepted. In the case of late submission, a grade 0
is given.
● No deadline extensions will be given.
● You will lose 50 points if the program does not compile on the online compiler,
https://repl.it/languages/c.
● 5 points will be given for indentation and 5 for comments.
● Assignments must be done individually.
● Submitted codes will be automatically checked using tools that detect plagiarism.
● You may be asked to explain your code and rewrite a part of it in front of the
instructors.
● Please submit each task in a separate .c file naming as task1.c, task2.c etc. for
each task of the assignment and submit in a zip file to the submission box of
Moodle.
● All files must be with .c format. All other formats of files will not be accepted.

如有需要,请加QQ:99515681 或WX:codehelp

标签:151,palindrome,CSCI,number,should,will,program,row
来源: https://www.cnblogs.com/okgolld/p/14460281.html