| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1281 人关注过本帖
标题:[求助]救救小妹吧。。不会做的 c语言题。。>o
只看楼主 加入收藏
cwande
Rank: 2
等 级:新手上路
威 望:3
帖 子:333
专家分:0
注 册:2006-8-18
收藏
得分:0 

7*12的矩形,14个单词.
枚举每个单词,从格子的每个点的八个方向进行判断,
复杂度O(7*12*14*8*len),还是很快的说.只不过有些细节注意一下就是了.
len为单词的长度.


汗,都懒得写代码了.......... cheat了一个威望,哈.....
2006-08-30 17:47
nicole
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-8-29
收藏
得分:0 

终于从导员那儿求到提示了。。

但还是不明白。。@.@

希望各位高手哥哥可以看得明吧。。 拜托拉。。

-----------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>

/****************************************************************/
/* Constants and structure definitions */

/* Constant for the maximum size of all arrays */
#define MAXSIZE 50

/* Structure to hold information about the rectangular grid */
typedef struct
{
/* The letters in the grid */
char letters[MAXSIZE][MAXSIZE];
/* The number of rows in the grid */
int nRows;
/* The number of columns in the grid */
int nCols;
} GRID;

/* Structure to hold information about a search position */
typedef struct
{
/* The row number, starting from 0 */
int row;
/* The column number, starting from 0 */
int col;
} LOCATION;

/* Structure to hold information about the amount to move in a single
step of the searching process */
typedef struct
{
/* The amount to move in the row-direction: either -1, 0, or 1
depending on the direction of the search */
int deltaRow;
/* The amount to move in the column-direction: either -1, 0,
or 1 depending on the direction of the search */
int deltaColumn;
} MOVEMENT;

/* Enumeration for the possible search directions */
typedef enum {UP, DIAGUPRIGHT, RIGHT, DIAGDOWNRIGHT,
DOWN, DIAGDOWNLEFT, LEFT, DIAGUPLEFT} DIRECTION;

/****************************************************************/
/* Global variable definitions */
/* You should not need to add to this list */

/* A global variable for the rectangular grid of letters */
GRID grid;

/****************************************************************/
/* Functions */

/*
isValidGridEntry(c) returns true iff c is a valid character that can
appear in a grid-file.
*/
static bool isValidGridEntry(char c)
{
}

/*
isValidChar(c) returns true iff c is a valid character that can appear
in a words-file.
*/
static bool isValidChar(char c)
{
}

/*
trimLine(line) removes any trailing new-line or carriage-return
characters from the end of line.
*/
static void trimLine(char line[])
{
}

/*
readGrid(filename) reads the contents of the file named filename as a
grid-file, "filling" the grid global variable with information read
from the file. The function terminates the program if the file is
not a valid grid-file or if the corresponding grid would be too large
to store in the grid global variable.
*/
static void readGrid(char filename[])
{
}

/*
displayGrid(void) displays the rectangular grid of characters held
in the grid global variable.
*/
static void displayGrid(void)
{
}

/*
move(dir) returns a MOVEMENT structure that indicates how much to vary
an iteration through the rows and columns of the grid for a single
step of the searching process, when searching in a dir direction.
e.g. move(UP)={-1,0}; move(RIGHT)={0,1}; move(DIAGUPLEFT)={-1,-1}
*/
static MOVEMENT move(DIRECTION dir)
{
}

/*
isMatch(c, gridLetter) returns true iff c matches the (potentially
highlighted) gridLetter.
*/
static bool isMatch(char c, char gridLetter)
{
}

/*
searchForm(word, loc, dir) returns true iff word appears in the grid
starting at position loc in the dir direction.
*/
static bool searchFrom(char word[], LOCATION loc, DIRECTION dir)
{
}

/*
highlightLetter(c) returns the highlighted version of c.
*/
static char highlightLetter(char c)
{
}

/*
foundWord(word, loc, dir) highlights word in the grid. This function
assumes word has already been found in the grid starting at position
loc in the dir direction.
*/
static void foundWord(char word[], LOCATION loc, DIRECTION dir)
{
}

/*
search(word) returns the the number of times word appears in the grid.
*/
static int search(char word[])
{
}

/*
processWords(filename) reads the contents of the file named filename
as a words-file, searching for each word in turn in the grid. The
function terminates the program if the file is not a valid words-file.
The function also reports whether each word the file found in the
grid and the total number of words from the file found in the grid.
*/
static void processWords(char filename[])
{
}

/****************************************************************/
/* The main program */

int main(int argc, char *argv[])
{
/* Exit with an error if the the number of arguments (including
the name of the executable) is not 3 */
if(argc != 3)
{
fprintf(stderr, "Usage: %s grid-file words-file\n", argv[0]);
exit(EXIT_FAILURE);
}
else
{
/* Read the grid from file */
readGrid(argv[1]);
printf("Read grid from '%s'.", argv[1]);
printf(" The initial grid is:\n");
/* Display the contents of the grid */
displayGrid();

printf("\nProcessing words from file '%s'.\n", argv[2]);
/* Search for words, highlighting matches in the grid */
processWords(argv[2]);

printf("\nFinished task.");
printf(" The final grid is:\n");
/* Redisplay the contents of the grid */
displayGrid();

/* Finished successfully! */
exit(EXIT_SUCCESS);
}
return 0;
}
2006-08-31 12:00
cdmalcl
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:24
帖 子:4091
专家分:524
注 册:2005-9-23
收藏
得分:0 

能把你的思路说一下么?

2006-08-31 13:11
wuyuqingzhu
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2006-5-24
收藏
得分:0 

看来得好好学学英语了,不然连注释都看不懂#75

2006-08-31 17:04
cdmalcl
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:24
帖 子:4091
专家分:524
注 册:2005-9-23
收藏
得分:0 

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#define MAXSIZE 50
typedef struct{
char letters[MAXSIZE][MAXSIZE];
int nRows;
int nCols;} GRID;
typedef struct{
int row;
int col;} LOCATION;
typedef struct{
int deltaRow;
int deltaColumn;} MOVEMENT;
typedef enum
{UP, DIAGUPRIGHT, RIGHT, DIAGDOWNRIGHT,DOWN, DIAGDOWNLEFT, LEFT, DIAGUPLEFT} DIRECTION;
GRID grid;
static bool isValidGridEntry(char c){}
static bool isValidChar(char c){}
static void trimLine(char line[]){}
static void readGrid(char filename[]){}
static void displayGrid(void){}
static MOVEMENT move(DIRECTION dir){}
static bool isMatch(char c, char gridLetter){}
static bool searchFrom(char word[], LOCATION loc, DIRECTION dir){}
static char highlightLetter(char c){}
static void foundWord(char word[], LOCATION loc, DIRECTION dir){}
static int search(char word[]){}
static void processWords(char filename[]){}
int main(int argc, char *argv[])
{
if(argc != 3)
{
fprintf(stderr, "Usage: %s grid-file words-file\n", argv[0]);
exit(EXIT_FAILURE);
}
else
{
readGrid(argv[1]);
printf("Read grid from '%s'.", argv[1]);
printf(" The initial grid is:\n");
displayGrid();
printf("\nProcessing words from file '%s'.\n", argv[2]);
processWords(argv[2]);
printf("\nFinished task.");
printf(" The final grid is:\n");
displayGrid();
exit(EXIT_SUCCESS);
}
return 0;
}
这是什么啊 ?连个回车都没有!
我整理了半天~~
汗!

我做了个,你看看行不行:
#include "stdio.h"
#include "conio.h"

char word[7][12]={"dogxbxxxnoon",
"bhellotherec",
"akciuqbrownm",
"xxxgexlahjij",
"xbzoxvuxxxox",
"xlxdzxexxxjx",
"xuxxblxnkgod" };

char find[14][18]={ "hello",
"dog",
"brown",
"join",
"row",
"quick",
"averyverylongword",
"noon",
"z",
"blue",
"blunt",
"help",
"even",
"blink" };

int putf_x[26][30],putf_y[26][30];
int putf_n[26],outnum[14];

void unite();
void findnum();
void outresult();

main()
{
unite();
findnum();
outresult();
getch();
}

void unite()
{
int i,j;
int wr;


for(i=0;i<26;i++)
putf_n[i]=0;

for(i=0;i<7;i++)
for(j=0;j<12;j++)
{
wr=word[i][j]-97;

putf_x[wr][putf_n[wr]]=j;
putf_y[wr][putf_n[wr]]=i;
putf_n[wr]++;
}

}

void findnum()
{
int i,j=0;
int f_x,f_y,x,y,l,w;
int wr;
char xj;

for(i=0;i<14;i++)
{
j=0;
wr=find[i][j]-97;
if(!find[i][1])
{
outnum[i]=putf_n[wr];
}
else
{
for(l=0;l<putf_n[wr];l++)
{
f_x=putf_x[wr][l];
f_y=putf_y[wr][l];

for(w=0;w<8;w++)
{
j=0;
x=f_x;
y=f_y;

while(find[i][j]!='\0'&&x<12)
{
switch(w)
{
case 0:x++; y--;break;
case 1:x--; y++;break;
case 2:x++; y++;break;
case 3:x--; y--;break;
case 4:y--;break;
case 5:y++;break;
case 6:x++;break;
case 7:x--;break;
default:;
}

if(x<=12&&y<=7&&x>=0&&y>=0)
{
j++;


if(find[i][j]=='\0')
{
outnum[i]++;
}

if(word[y][x] != find[i][j])
{
x=90;
}
}
else
{
x=90;
}
}

}
}
}
}
}

void outresult()
{
int i;

for(i=0;i<14;i++)
{
if(outnum[i])
{
cprintf("The word ");
highvideo();
cprintf("%s",find[i]);
lowvideo();
cprintf(" was found "); highvideo();
cprintf("%d",outnum[i]);lowvideo();
printf(" time in the grid\n");
}
else
{
cprintf("The word "); highvideo();
cprintf("%s",find[i]);lowvideo();
cprintf(" was found ");highvideo();
cprintf("NOT"); lowvideo();
printf(" time in the grid\n");
}
}
}

2006-09-01 16:13
快速回复:[求助]救救小妹吧。。不会做的 c语言题。。>o
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012535 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved