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. [
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)
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!");