////////////////////////////////////////////////////////
// ZOJ:1745
// 本题出现最多的就是输出格式错误的问题,被题目调戏了
///////////////////////////////////////////////////////
#include "stdio.h"
#include "math.h"
int main(void)
{
int cookiepos[500] = {0};
int pos[500][500] = {0};
int prepos;
int dis;
int i = 0;
int k;
int m;
int x, y;
while (scanf("%d", &cookiepos[i]))
{
if (cookiepos[i] >= 5280)
{
break;
}
k = 0;
while (scanf("%d", &pos[i][k]))
{
if (cookiepos[i] == pos[i][k])
{
break;
}
k++;
}
i++;
}
m = i;
x = 0;
while (m-- > 0)
{
y = 0;
dis = abs(0 - cookiepos[x]);
prepos = 0;
while (pos[x][y] != cookiepos[x])
{
if (abs(pos[x][y] - cookiepos[x]) > dis)
{
printf("Moving from %d to %d: colder./n", prepos, pos[x][y]);
prepos = pos[x][y];
dis = abs(pos[x][y] - cookiepos[x]);
}
else if (abs(pos[x][y] - cookiepos[x]) < dis)
{
printf("Moving from %d to %d: warmer./n", prepos, pos[x][y]);
prepos = pos[x][y];
dis = abs(pos[x][y] - cookiepos[x]);
}
else if (abs(pos[x][y] - cookiepos[x]) == dis)
{
printf("Moving from %d to %d: same./n", prepos, pos[x][y]);
prepos = pos[x][y];
dis = abs(pos[x][y] - cookiepos[x]);
}
y++;
}
printf("Moving from %d to %d: found it!/n", prepos, pos[x][y]);
if (m >= 1)
{
printf("/n");
}
x++;
}
return 0;
}
zoj 1745 又是简单题
最新推荐文章于 2015-08-28 01:19:16 发布
本文提供了一段解决ZOJ 1745问题的C语言代码,该代码通过判断不同位置与目标位置之间的距离变化来输出移动方向的提示,如更接近目标则输出warmer,反之则输出colder。
1060

被折叠的 条评论
为什么被折叠?



