c语言(Unix)英文

http://www.ece.arizona.edu/~ece175/assignments/assignment08.pdf

问题在这个页面的pdf文件
希望予以解答..
最新回答
你们不会忘记我

2024-11-23 12:20:26

1.The file "sudoku-solution.txt" contains integer values for a Sudoku puzzle -- two dimensional integer array with 9 rows and 9 columns. Write a program that reads this file as input and prints out if the file provides a proper solution to the Sudoku puzzle or not.
1.文件“sudoku-solution.txt”包含数独游戏的整型数,该二维整型数组有9行9列。编写一个程序读取该文件中的数,并判断是否能构成一个数独;
For the rules of Sudoku, check Wikipedia. [
http://en.wikipedia.org/wiki/Sudoku
]
查看维基网站:
http://en.wikipedia.org/wiki/Sudoku
可以获取数独游戏的相关规则

Example File Format:
例子:
1 2 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
2 3 4 5 6 7 8 9 1
5 6 7 8 9 1 2 3 4
8 9 1 2 3 4 5 6 7
3 4 5 6 7 8 9 1 2
6 7 8 9 1 2 3 4 5
9 1 2 3 4 5 6 7 8

Result: Solution is Correct!
结果:解答正确
2. Write a program that identifies if a given string is a palindrome or not. A palindrome is one where a string (or
word) reads the same when read forward and reverse.
Example: "Level" : palindrome "Lists": not a palindrome
Call this program string-palindrome.c.
2.编写一程序判断所给字符串是否为回文,回文是指一个字符串或单词,从前往后和从后往前读都是一样的
例如:"Level":回文 "Lists":不是回文
把这样的程序叫做 string-palindrome.c(可以翻译为:回文字符串.c)
┌胖胖糖〃

2024-11-23 17:12:29

sudoku-verifier.c:

//---------------------------------------------------------------------------

#include <stdio.h>

int issudu(int sd[9][9])
{
int i,j,k,sx,sy;
for (i = 0; i<9; i++) {
for (k=1; k<10; k++) {
sx=0;
sy=0;
for (j=0; j<9; j++) {
sx+=sd[i][j]==k?1:0;
if (sx>1) return 0;
sy+=sd[j][i]==k?1:0;
if (sy>1) return 0;

}

}
}
return 1;
}
int main(int argc, char* argv[])
{
FILE *f;
int sd[9][9],i,j;
if (argc>1) f=fopen(argv[1],"r");
else f=fopen("sudoku-solution.txt","r");

for (i = 0; i<9; i++){
for (j=0; j<9; j++){
fscanf(f,"%d",&sd[i][j]);
printf("%-2d",sd[i][j]);
}
putchar('\n');
}
fclose(f);
puts(issudu(sd)?"Result: Solution is Correct!":"Result: Solution is incorrect!");

return 0;
}
//---------------------------------------------------------------------------

string-palindrome.c:

//---------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
int main(void)
{
char str[80];
int i,len;
gets(str);
len=strlen(str)/2;
for (i = 0; i<len; i++) {
if (str[i]!=str[strlen(str)-1-i]) {
printf("%s : not a palindrome\n",str);
break;
}
}
if (i==len) {
printf( "%s : palindrome\n",str);
}
return 0;
}
//---------------------------------------------------------------------------