| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

已结贴   问题点数：3  回复次数：3

31

2,s
#include<stdio.h>
#include<string.h>
int main()
{
char a[20],m,n;
char d='1';
char b[4];
int i,k=0;
int x=0;
int y=0;

for(i=0;i<20;i++)
{
scanf("%c",&a[i]);
if(a[i]=='\n')break;
else k++;
}

for(i=0;i<k;i++)
{
if(d=='1')
{
if(a[i]=='1')
{
x-=1;
continue;
}
if(a[i]=='2')
{
y+=1;
d='2';
continue;
}
if(a[i]=='3')
{
y-=1;
d='3';
continue;
}
}
if(d=='2')
{
if(a[i]=='1')
{
y+=1;
continue;
}
if(a[i]=='2')
{
x+=1;
d='4';
continue;
}
if(a[i]=='3')
{
x-=1;
d='1';
continue;
}
}
if(d=='3')
{
if(a[i]=='1')
{
y-=1;
continue;
}
if(a[i]=='2')
{
x=x-1;
d='1';
continue;
}
if(a[i]=='3')
{
x+=1;
d='4';
continue;
}
}
if(d=='4')
{
if(a[i]=='1')
{
y+=1;
continue;
}
if(a[i]=='2')
{
y-=1;
d='3';
continue;
}
if(a[i]=='3')
{
y+=1;
d='2';
continue;
}
}
}

if(x==0)
{
if(y>0)
printf("%d,n\n",k);
else if(y<0)
printf("%d,s\n",k);
}
if(y==0)
{
if(x>0)
printf("%d,e\n",k);
else if(x<0)
printf("%d,w\n",k);
}
if(x>0)
{
if(y>0)
printf("%d,en\n",k);
else if(y<0)
printf("%d,es\n",k);
}
if(x<0)
{
if(y>0)
printf("%d,nw\n",k);
else if(y<0)
printf("%d,sw\n",k);
}
return 0;
}

得分:3

31

2,s

131

3,sw

得分:0

```#include <stdio.h>

int main( void )
{
char s[21];
scanf( "%s", s );

unsigned count=0, direction=2;
int xy[2] = { 0, 0 };
for( const char* p=s; *p; ++p,++count )
{
direction = (direction + (*p-'0')%3 +3)%4;
xy[direction%2] += 1-(direction+1)/2%2*2;
}
printf( "%u,", count );

const char* result[3][3] = { {"sw","w","nw"},{"s","?","n"},{"es","e","en"} };
puts( result[1+(xy[0]>0)-(xy[0]<0)][1+(xy[1]>0)-(xy[1]<0)] );

}```

得分:0

• 4
• 1/1页
• 1