c语言兔子的谎言,C语言2d阵列趣味游戏填字游戏(C language 2d Array Fun Game Crossword)...

I am given a crossword crossword[20][20] its already fulled with words so i dont need to generate. I need to scan for words horizontally ONLY and put them in a new array. One word per line so the new array will be array[40][20].

NOTE: The crossword has maximum 40 horizontal words! So i only need 40 lines in the array. If the words<40 then the other cells in the array will remain '\0'.

The black boxes are the '*'.

The given crossword is this:

char crossword[20][20]={

{'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*'},

{'*','T','Y','P','E','*','*','*','*','G','U','I','T','A','R','I','S','T','*','*'},

{'*','E','*','*','V','A','I','N','*','A','*','*','*','V','*','*','T','*','I','*'},

{'*','R','O','M','E','*','*','*','*','M','A','R','R','I','A','G','E','*','N','*'},

{'*','R','*','*','N','O','O','D','L','E','*','O','*','A','*','*','A','N','T','*'},

{'*','I','N','*','*','*','*','O','*','*','*','P','E','T','R','O','L','*','I','*'},

{'*','F','*','C','*','C','U','T','*','L','I','E','*','I','*','A','T','O','M','*'},

{'*','I','*','O','*','U','*','*','M','*','N','*','M','O','U','T','H','*','A','*'},

{'*','E','N','V','E','L','O','P','E','*','F','*','I','N','*','H','*','A','T','*'},

{'*','D','*','E','*','T','*','*','A','*','E','*','N','*','*','*','A','G','E','*'},

{'*','*','A','R','T','*','I','N','T','E','R','I','O','R','*','A','*','O','*','*'},

{'*','K','*','*','O','*','R','*','*','A','T','*','R','O','B','B','E','R','Y','*'},

{'*','A','T','*','A','I','R','*','S','T','I','R','*','O','*','O','*','A','*','*'},

{'*','N','O','*','S','*','I','T','*','*','L','*','S','M','I','L','E','*','S','*'},

{'*','G','*','*','T','*','T','*','O','*','I','*','O','*','N','I','G','H','T','*'},

{'*','A','C','E','*','M','A','N','D','A','T','O','R','Y','*','T','O','*','O','*'},

{'*','R','*','N','Y','*','T','*','E','*','Y','*','T','*','*','I','*','*','P','*'},

{'*','O','*','D','O','*','E','*','*','*','*','I','*','O','Z','O','N','E','*','*'},

{'*','O','N','*','U','N','D','E','R','W','A','T','E','R','*','N','O','U','N','*'},

{'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*'}

};

So what i have done so far is this, but it is not correct because i do it with nerdy way...:

#include

#include

char cross[20][20]={

{'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*'},

{'*','T','Y','P','E','*','*','*','*','G','U','I','T','A','R','I','S','T','*','*'},

{'*','E','*','*','V','A','I','N','*','A','*','*','*','V','*','*','T','*','I','*'},

{'*','R','O','M','E','*','*','*','*','M','A','R','R','I','A','G','E','*','N','*'},

{'*','R','*','*','N','O','O','D','L','E','*','O','*','A','*','*','A','N','T','*'},

{'*','I','N','*','*','*','*','O','*','*','*','P','E','T','R','O','L','*','I','*'},

{'*','F','*','C','*','C','U','T','*','L','I','E','*','I','*','A','T','O','M','*'},

{'*','I','*','O','*','U','*','*','M','*','N','*','M','O','U','T','H','*','A','*'},

{'*','E','N','V','E','L','O','P','E','*','F','*','I','N','*','H','*','A','T','*'},

{'*','D','*','E','*','T','*','*','A','*','E','*','N','*','*','*','A','G','E','*'},

{'*','*','A','R','T','*','I','N','T','E','R','I','O','R','*','A','*','O','*','*'},

{'*','K','*','*','O','*','R','*','*','A','T','*','R','O','B','B','E','R','Y','*'},

{'*','A','T','*','A','I','R','*','S','T','I','R','*','O','*','O','*','A','*','*'},

{'*','N','O','*','S','*','I','T','*','*','L','*','S','M','I','L','E','*','S','*'},

{'*','G','*','*','T','*','T','*','O','*','I','*','O','*','N','I','G','H','T','*'},

{'*','A','C','E','*','M','A','N','D','A','T','O','R','Y','*','T','O','*','O','*'},

{'*','R','*','N','Y','*','T','*','E','*','Y','*','T','*','*','I','*','*','P','*'},

{'*','O','*','D','O','*','E','*','*','*','*','I','*','O','Z','O','N','E','*','*'},

{'*','O','N','*','U','N','D','E','R','W','A','T','E','R','*','N','O','U','N','*'},

{'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*'}

};

int main(){

int i, j, start_index, end_index, a, b, start_index1, end_index1;

char cross1[40][20], cross11[40][20];

for(i=0;i<40;i++){

for(j=0;j<20;j++){

cross1[i][j]='\0';

}

}

for(i=0;i<40;i++){

for(j=0;j<20;j++){

cross11[i][j]='\0';

}

}

for(i=0;i<19;i++){

start_index = -1;

end_index=-1;

start_index1 = -1;

end_index1=-1;

for(j=0;j<20;j++){

if(isalpha(cross[i][j]) && (!isalpha(cross[i][j-1])) && isalpha(cross[i][j+1]) && start_index==-1){

start_index = j;

}

if(isalpha(cross[i][j]) && (!isalpha(cross[i][j+1])) && isalpha(cross[i][j-1]) && end_index==-1){

end_index = j;

}

if(isalpha(cross[i][j]) && (!isalpha(cross[i][j-1])) && isalpha(cross[i][j+1])){

start_index1 = j;

}

if(isalpha(cross[i][j]) && (!isalpha(cross[i][j+1])) && isalpha(cross[i][j-1])){

end_index1 = j;

}

}

for(a=start_index,b=0;a<=end_index;a++,b++){

cross1[i][b]=cross[i][a];

}

for(a=start_index1,b=0;a<=end_index1;a++,b++){

cross11[i][b]=cross[i][a];

}

}

printf("CROSS1\n");

for(i=0;i<20;i++){

for(j=0;j<20;j++){

printf("%c ", cross1[i][j]);

}

printf("\n");

}

printf("CROSS11\n");

for(i=0;i<20;i++){

for(j=0;j<20;j++){

printf("%c ", cross11[i][j]);

}

printf("\n");

}

return 0;

}

And the output is this:

CROSS1

TYPE

VAIN

ROME

NOODLE

IN

CUT

MOUTH

ENVELOPE

AGE

ART

AT

AT

NO

NIGHT

ACE

NY

DO

ON

CROSS11

GUITARIST

VAIN

MARRIAGE

ANT

PETROL

ATOM

MOUTH

AT

AGE

INTERIOR

ROBBERY

STIR

SMILE

NIGHT

TO

NY

OZONE

NOUN

The problem is that i want it in one arrray not in two (cross1, cross11) and also some words are printed twice (both in cross1 and cross11 like the "MOUTH"), also another problem is that some words dont even printed like the: "LIE"

Any help appreciated and rewarded!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值