早教吧作业答案频道 -->其他-->
各位编程的高手朋友们请帮我解决这个问题吧急!Youaregivenawordpuzzlewhichyoumustsolve.Thedatafilecontainsthenumberofwordstolocate(int)followedbythewords,oneperline.Nextisthesizeoftheboardasrows(i
题目详情
各位编程的高手朋友们 请帮我解决这个问题吧 急!
You are given a word puzzle which you must solve. The data file contains the number of
words to locate (int) followed by the words, one per line. Next is the size of the board
as rows (int) and columns (int) followed by the actual board, one row per line. For
example, the supplied data file consists of 21 words followed by a 25x25 word board.
You are to read the words into a ragged array. This array will consist of 21 rows, where
each row represents 1 word. The board should be read into a second 25x25 char matrix.
For each word in the word list, identify its location in the board. For output, write the
board with the located words to an ASCIIDisplayer.
Suggestions
How you should proceed with the solution and things to think about.
1. Create the data structures for the ragged array to hold the word list. Each word in
the list will represent a right sized char array. The board is simply a 25x25
char matrix.
2. Read the data file loading both the word list and the board. When reading the
word list consider reading a word as a String, and then using the
toCharArray method to convert the string to a right-sized character array.
3. Write a small test routine which prints both of these data structures to a displayer.
It is nice to know that your program works correctly up to this point. The output
should match the input.
4. Write a search routine which, for each character, will search all 8 directions for
each word in the list. My solution had 3 nested for loops. For each location in the
board (2 indices, hence 2 nested loops), find the word (1 index into the word list).
The actual character by character matching will require additional indexing.
5. Consider using a 2nd 25x25 char matrix for output. Once a word is found, write
it into this output matrix. Printing the output matrix will give the above output.
The output matrix should be initialized to blank characters.
You are given a word puzzle which you must solve. The data file contains the number of
words to locate (int) followed by the words, one per line. Next is the size of the board
as rows (int) and columns (int) followed by the actual board, one row per line. For
example, the supplied data file consists of 21 words followed by a 25x25 word board.
You are to read the words into a ragged array. This array will consist of 21 rows, where
each row represents 1 word. The board should be read into a second 25x25 char matrix.
For each word in the word list, identify its location in the board. For output, write the
board with the located words to an ASCIIDisplayer.
Suggestions
How you should proceed with the solution and things to think about.
1. Create the data structures for the ragged array to hold the word list. Each word in
the list will represent a right sized char array. The board is simply a 25x25
char matrix.
2. Read the data file loading both the word list and the board. When reading the
word list consider reading a word as a String, and then using the
toCharArray method to convert the string to a right-sized character array.
3. Write a small test routine which prints both of these data structures to a displayer.
It is nice to know that your program works correctly up to this point. The output
should match the input.
4. Write a search routine which, for each character, will search all 8 directions for
each word in the list. My solution had 3 nested for loops. For each location in the
board (2 indices, hence 2 nested loops), find the word (1 index into the word list).
The actual character by character matching will require additional indexing.
5. Consider using a 2nd 25x25 char matrix for output. Once a word is found, write
it into this output matrix. Printing the output matrix will give the above output.
The output matrix should be initialized to blank characters.
▼优质解答
答案和解析
1.scanf的用法错误
是scanf("%f",&a[i][j]);而不是scanf("%f",a[i][j]);
2.printf的用法错误
是printf("%6f",a[i][j])或者printf("%d",(int)a[i][j]);而不是printf("%6d",a[i][j]);数组的声明是float类型则输出数据时也要指定好格式
3.函数传参错误
float sum(float a[][6],int j)的参数传递如下
float a[4][6];
sum(a,j);而不是sum(a[i][6],j)或sum(a[][6],j);
应该传递一个2维数组指针,而你传递的是一个float值或者是一个维数组指针
4.代码混乱
for(i=0;i<3;i++)
for(j=0;j<5;j++)
printf("%6d",a[i][j]);
printf("\n");
根本达不到输出一行数据后换行的要求
要改为
for(i=0;i<3;i++)
{
for(j=0;j<5;j++)
printf("%d ",(int)a[i][j]);
printf("\n");
}
另外:你举的例子的输出结果不正确
以下代码在VC6中运行正确
#include
float student_aver(float a[][6],int i);
float sum(float a[][6],int j);
float one_grade_aver(float a[][6],int j);
int main()
{
int i,j;
float a[4][6];
a[3][5]=0;
printf("please enter the grades:\n");
for(i=0;i<3;i++)
{
for(j=0;j<5;j++)
scanf("%f",&a[i][j]);
}
printf("Input:\n");
for(i=0;i<3;i++)
{
for(j=0;j<5;j++)
printf("%d ",(int)a[i][j]);
printf("\n");
}
for(i=0;i<3;i++)
a[i][5]=student_aver(a,i);
for(j=0;j<5;j++)
a[3][j]=sum(a,j);
printf("Output:\n");
for(i=0;i<4;i++)
{
for(j=0;j<6;j++)
printf("%0.1f ",a[i][j]);
printf("\n");
}
printf("Average:\n");
for(j=0;j<5;j++)
printf("%4.1f ",one_grade_aver(a,j));
printf("\n");
return 0;
}
float student_aver(float a[][6],int i)
{
int k;
float sum=0,aver;
for(k=0;k<5;k++)
sum=sum+a[i][k];
aver=sum/5;
return (aver);
}
float sum(float a[][6],int j)
{
int k;
float sum=0;
for(k=0;k<3;k++)
sum=sum+a[k][j];
return (sum);
}
float one_grade_aver(float a[][6],int j)
{
float aver;
aver=sum(a,j)/3;
return (aver);
}
是scanf("%f",&a[i][j]);而不是scanf("%f",a[i][j]);
2.printf的用法错误
是printf("%6f",a[i][j])或者printf("%d",(int)a[i][j]);而不是printf("%6d",a[i][j]);数组的声明是float类型则输出数据时也要指定好格式
3.函数传参错误
float sum(float a[][6],int j)的参数传递如下
float a[4][6];
sum(a,j);而不是sum(a[i][6],j)或sum(a[][6],j);
应该传递一个2维数组指针,而你传递的是一个float值或者是一个维数组指针
4.代码混乱
for(i=0;i<3;i++)
for(j=0;j<5;j++)
printf("%6d",a[i][j]);
printf("\n");
根本达不到输出一行数据后换行的要求
要改为
for(i=0;i<3;i++)
{
for(j=0;j<5;j++)
printf("%d ",(int)a[i][j]);
printf("\n");
}
另外:你举的例子的输出结果不正确
以下代码在VC6中运行正确
#include
float student_aver(float a[][6],int i);
float sum(float a[][6],int j);
float one_grade_aver(float a[][6],int j);
int main()
{
int i,j;
float a[4][6];
a[3][5]=0;
printf("please enter the grades:\n");
for(i=0;i<3;i++)
{
for(j=0;j<5;j++)
scanf("%f",&a[i][j]);
}
printf("Input:\n");
for(i=0;i<3;i++)
{
for(j=0;j<5;j++)
printf("%d ",(int)a[i][j]);
printf("\n");
}
for(i=0;i<3;i++)
a[i][5]=student_aver(a,i);
for(j=0;j<5;j++)
a[3][j]=sum(a,j);
printf("Output:\n");
for(i=0;i<4;i++)
{
for(j=0;j<6;j++)
printf("%0.1f ",a[i][j]);
printf("\n");
}
printf("Average:\n");
for(j=0;j<5;j++)
printf("%4.1f ",one_grade_aver(a,j));
printf("\n");
return 0;
}
float student_aver(float a[][6],int i)
{
int k;
float sum=0,aver;
for(k=0;k<5;k++)
sum=sum+a[i][k];
aver=sum/5;
return (aver);
}
float sum(float a[][6],int j)
{
int k;
float sum=0;
for(k=0;k<3;k++)
sum=sum+a[k][j];
return (sum);
}
float one_grade_aver(float a[][6],int j)
{
float aver;
aver=sum(a,j)/3;
return (aver);
}
看了 各位编程的高手朋友们请帮我解...的网友还看了以下:
我有几道六年级数学题不会请大家帮帮我,帮我解一下题第一大题.一个半径为2里面的铁片的圆形铁片,它的 2020-04-27 …
我的数学不怎么好,尤其是分式方程解应用题,一窍不通,求高手教不是解方程啊是分式方程解应用题啊大家帮 2020-05-13 …
关于数学微分方程的几道题目.1.( d^2y)/dx^2 +4y=0 的通解为多少.2.y"" = 2020-05-13 …
1.列举古代史上两次封建化改革2.中国古代史上三个分裂时期请帮小妹解难!答题要简洁明了!1.列举古 2020-06-07 …
求初中英语作文题目,要求是帮助别人解决问题的题材,要有具体题目要求.谢谢.最好是帮助外国朋友适应中 2020-06-07 …
请高手帮帮我解决几个寒假作业问题,帮帮我解决问题,好的话会考虑额外加分!(要精彩)他的身材真高大, 2020-06-29 …
关于单纯形法解的问题(大家帮帮忙啊)用单纯形法做题,表列到最后时怎么判断那是唯一解?无穷解?无界解 2020-07-31 …
帮我解这道题求R1和R2的值IR=(I1-I)(R1+R2)I(R+R2)=(I2-I)R1联立以上 2020-10-30 …
在新课标中总目标中包括“解决问题”这以目标,但我又不能十分理解他和“数学问题解决能力”有什么联系和区 2020-11-21 …
图形可以帮助刻画和描述问题;图形可以帮助发现和寻找解决问题的思路;图形可以帮助表述和记忆一些结果.积 2020-12-09 …