-2 c++ arrays multidimensional-array
需要帮助找出问题readPuzzle和printPuzzle功能有什么问题.SetOfSmallInts是包含{1,2,3,4,5,6,7,8,9}这些数字的任何组合的集合.singletonSet(s)在一组中存储单个数字.无论我在程序上运行什么输入,它只输出1.即使所有输入都是' - ',输出也是81 1.有什么建议?Puzzle中的Puzzle类型构成一个数组SetofSmallInts [9][9].
//==============================================================
// readPuzzle
//==============================================================
// Reads in puzzle p from the standard input.
//==============================================================
void readPuzzle(Puzzle p)
{
int i, j;
SetOfSmallInts s;
s = rangeSet(1, 9);
char n;
for(i = 0; i < 9; i++)
{
for(j = 0; j < 9; j++)
{
n = scanf("%c", &n);
if (n == '-')
{
p[i][j]= s;
}
else if(n==1 || n==2 || n==3 || n==4 || n==5 || n==6 ||
n==7 || n==8 || n==9)
{
p[i][j]= singletonSet(n);
}
}
}
}
//==============================================================
// printPuzzle
//==============================================================
// Prints in puzzle p.
//==============================================================
void printPuzzle(Puzzle p)
{
int i, j, s;
SetOfSmallInts x;
for(i = 0; i < 9; i++)
{
for(j = 0; j < 9; j++)
{
x = p[i][j];
if(isEmpty(x))
{
printf("%i ", 0);
}
else if(isSingleton(x)) //returns true if x hold Singleton set
{
s = smallest(x); // returns the smallest member of s
printf("%i ", s);
}
else
{
printf("%c ", '-');
}
}
}
}
//==============================================================
// showPuzzle
//==============================================================
// Shows in puzzle p in a format that can be used for debugging
//==============================================================
//==============================================================
// main
//==============================================================
int main(int argc, char** argv)
{
Puzzle p;
readPuzzle(p);
printPuzzle(p);
return 0;
}
Run Code Online (Sandbox Code Playgroud)