海归网首页   海归宣言   导航   博客   广告位价格  
海归论坛首页 会员列表 
收 藏 夹 
论坛帮助 
登录 | 登录并检查站内短信 | 个人设置 论坛首页 |  排行榜  |  在线私聊 |  专题 | 版规 | 搜索  | RSS  | 注册 | 活动日历
主题: 提上来,回答悠悠小草 [每日一题] 之 谁养鱼?
回复主题   printer-friendly view    海归论坛首页 -> 海归茶馆           焦点讨论 | 精华区 | 嘉宾沙龙 | 白领丽人沙龙
  阅读上一个主题 :: 阅读下一个主题
作者 提上来,回答悠悠小草 [每日一题] 之 谁养鱼?   
所跟贴 虽然我的答案是你结果中的第6个,不得不承认我是“不求甚解”啊 :-) -- 海蓝 - (23 Byte) 2005-4-19 周二, 02:20 (380 reads)
书生
[博客]
[个人文集]





游客










文章标题: 这下献丑了 (414 reads)      时间: 2005-4-19 周二, 02:45      

作者:游客海归茶馆 发贴, 来自【海归网】 http://www.haiguinet.com

不能代表海归网的水平。

#include
#include

char strHouse[5][100] = { "Red", "White", "Blue", "Green", "Yellow" };
char strNation[5][100] = { "English", "Danish", "Norwegian", "Germany", "Swedish" };
char strSmoke[5][100] = { "PALL MALL", "Mixed", "DUNHILL", "BLUE MASTER", "PRINCE" };
char strDrink[5][100] = { "Tea", "Coffee", "Water", "Milk", "Beer" };
char strPet[5][100] = { "Cat", "Dog", "Fish", "Bird", "Horse" };

int Count[5] = {0,0,0,0,0};

int Num[5][5] =
{
{ 0, 1, 2, 3, 4 },
{ 0, 1, 2, 3, 4 },
{ 0, 1, 2, 3, 4 },
{ 0, 1, 2, 3, 4 },
{ 0, 1, 2, 3, 4 }
};

int Flag[5][5] =
{
{ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 }
};

int House = 0;
int Nation = 1;
int Smoke = 2;
int Drink = 3;
int Pet = 4;

int Block[5][5] =
{
{ 0, 1, 2, 3, 4 },
{ 0, 1, 2, 3, 4 },
{ 0, 1, 2, 3, 4 },
{ 0, 1, 2, 3, 4 },
{ 0, 1, 2, 3, 4 }
};

int GetIndex(int iType, int val)
{
int i;
for (i=0;i<5;i++)
if (Block[iType][i] == val)
return i;
}



int IsNeighbor(int i, int j)
{
if (i != j)
{
if (i + 1 == j || j + 1 == i)
return 1;
}

return 0;
}

int FoundOneMatch()
{
if (
GetIndex(Nation, 2) == 0 &&
GetIndex(Drink, 3) == 2 &&
GetIndex(House, 0) == GetIndex(Nation, 0) &&
GetIndex(Nation, 4) == GetIndex(Pet, 1) &&
GetIndex(Nation, 1) == GetIndex(Drink, 0) &&
GetIndex(House, 3) == GetIndex(Drink, 1) &&
GetIndex(Smoke, 0) == GetIndex(Pet, 3) &&
GetIndex(House, 4) == GetIndex(Smoke, 2) &&
GetIndex(Smoke, 3) == GetIndex(Drink, 4) &&
GetIndex(Nation, 3) == GetIndex(Smoke, 4) &&
GetIndex(House, 3) < GetIndex(House, 1) &&
IsNeighbor(GetIndex(Smoke, 1), GetIndex(Pet, 0)) &&
IsNeighbor(GetIndex(Pet, 4), GetIndex(Smoke, 2)) &&
IsNeighbor(GetIndex(Nation, 2), GetIndex(House, 2)) &&
IsNeighbor(GetIndex(Smoke, 1), GetIndex(Drink, 2))
)
return 1;
return 0;
}

void OutputMatch()
{
int i;

printf("\n");
// 1 2 3 4
// 01234567890123456789012345678901234567890123456789
printf("====================================================\n");
printf("House Nation Smoke Drink Pet\n");
printf("====================================================\n");
for (i=0; i<5; i++)
printf("%-8s %-8s %-12s %-8s %-8s\n",
strHouse[Block[0][i]],
strNation[Block[1][i]],
strSmoke[Block[2][i]],
strDrink[Block[3][i]],
strPet[Block[4][i]]);
printf("====================================================\n");
}

void GoThrough(int iType)
{
int number = 5;
int i, j;

Count[iType]++;

for(i=0;i {
Num[iType][i]=i;
Flag[iType][i]=1;

printf("%d %d %d %d %d",
Count[0],
Count[1],
Count[2],
Count[3],
Count[4]);
}

while(1)
{
for(j=0;j {
Block[iType][j] = Num[iType][j];
}

if (iType < 4)
{
//printf("%d %d %d %d %d %d\n",
// iType,
// Block[iType][0],
// Block[iType][1],
// Block[iType][2],
// Block[iType][3],
// Block[iType][4]);
GoThrough(iType + 1);
}

if (iType == 4)
{
//printf(".");
//printf("%d %d %d %d %d %d\n",
// iType,
// Block[iType][0],
// Block[iType][1],
// Block[iType][2],
// Block[iType][3],
// Block[iType][4]);

//printf("%d %d %d %d %d\n",
// Flag[iType][0],
// Flag[iType][1],
// Flag[iType][2],
// Flag[iType][3],
// Flag[iType][4]);

//OutputMatch();

if (FoundOneMatch())
OutputMatch();
}

Flag[iType][Num[iType][number-1]] = 0;

for(i=number-2;i>=0;i--)
{
Flag[iType][Num[iType][i]] = 0;
if(Num[iType][i] }

if(i<0)
break;

for(j=Num[iType][i]+1;j {
if(!Flag[iType][j])
break;
}

Flag[iType][j]=1;
Num[iType][i]=j;

for(j=0,i++;i
if(!Flag[iType][j])
{
Num[iType][i++]=j;
Flag[iType][j]=1;
}
};
}

int main(void)
{
GoThrough(0);
return 0;
}


作者:游客海归茶馆 发贴, 来自【海归网】 http://www.haiguinet.com









相关主题
提上来,回答木辛大侠(断断续续歇了几天) 海归主坛 2014-1-03 周五, 21:37
提上来,回答【波儿的波】女人的身材怎么才叫好看?(原创照片)【美股图】 海归茶馆 2005-10-01 周六, 19:40
提上来,回答日资企业的报酬问题 海归论坛 2003-8-15 周五, 19:16
提上来,回答日资的报酬问题 海归论坛 2003-8-15 周五, 18:33
[问题回答]提上来答关于跃民的"gambling是否有trick... 海归酒吧 2006-10-09 周一, 01:25
[转帖]弟子提问 师父回答(二) 生活风情 2016-2-13 周六, 13:52
[转帖]弟子提问 师父回答(一) 生活风情 2016-2-09 周二, 12:01
忙里偷闲,回答兼声明兼感谢 海归酒吧 2009-3-23 周一, 16:14

返回顶端
显示文章:     
回复主题   printer-friendly view    海归论坛首页 -> 海归茶馆           焦点讨论 | 精华区 | 嘉宾沙龙 | 白领丽人沙龙 所有的时间均为 北京时间


 
论坛转跳:   
不能在本论坛发表新主题, 不能回复主题, 不能编辑自己的文章, 不能删除自己的文章, 不能发表投票, 您 不可以 发表活动帖子在本论坛, 不能添加附件不能下载文件, 
   热门标签 更多...
   论坛精华荟萃 更多...
   博客热门文章 更多...


海归网二次开发,based on phpbb
Copyright © 2005-2026 Haiguinet.com. All rights reserved.