题目的意思是给出两个方向和步骤,然后判是怎么判的
思路:先用map存一下4个方向,然后分别判顺逆时针能否达到
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
#define mod 10000007
#define mem(a,b) memset(a,b,sizeof a)
map<char,int>mp;
int main()
{
mp['^']=0;
mp['>']=1;
mp['v']=2;
mp['<']=3;
char a,b;
int n;
while(cin>>a>>b)
{
cin>>n;
n%=4;
int x1=mp[a]+n;
if(x1>3)x1-=4;
int x2=mp[a]-n;
if(x2<0)x2+=4;
if(x1==mp[b]&&x2!=mp[b])
printf("cw\n");
else if(x1!=mp[b]&&x2==mp[b])
printf("ccw\n");
else
printf("undefined\n");
}
return 0;
}
旋转玩具的方向判断

本文介绍了一个简单的算法问题,通过输入玩具的起始和结束位置及旋转时间,判断玩具的旋转方向是顺时针还是逆时针,或者无法确定。使用了C++实现,并通过映射表来快速匹配方向。


511

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



