您的位置:首页 > 其它

完美笔试第一题

2017-03-29 21:07 302 查看

include "stdafx.h"

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<mutex>
#include<stack>
#include<iomanip>
#include<math.h>
using namespace std;

int main()
{
int  w, h, x, n;
int pi = 3.1415926;
while (cin>>w>>h>>x>>n)
{
//判断每次弹出的小球是右侧还是左侧
//记录正在操作的边
int left = 0;
int right = 0;
int up = 0;
int down = 0;

while (n!=0)
{
n--;

while (down!=1)
{
if ((w - x) == h)
{
//cout << x << " " << endl;
down = 1;
left = 0;
right = 0;
up = 0;

}
else if ((w - x) < h) //碰到右面
{
if (down == 1)
{
down = 0;
left = 0;
right = 1;
up = 0;
}
else if (right==1)
{
down = 0;
left = 0;
right = 0;
up = 1;
}
else if (up == 1)
{
down = 0;
left = 1;
right = 0;
up = 0;
}
else
{
down = 1;
left = 0;
right = 0;
up = 0;
}

x = w - x;
int temp = w;
w = h;
h = temp;
}

else//碰到上面面
{
if (down == 1)
{
down = 0;
left = 0;
right = 0;
up = 1;
}
else if (right == 1)
{
down = 0;
left = 1;
right = 0;
up = 0;
}
else if (up == 1)
{
down = 1;
left = 0;
right = 0;
up = 0;
}
else
{
down = 0;
left = 0;
right = 1;
up = 0;
}

x = x + h;
int temp = w;
w = h;
h = temp;
}

}
if (n != 0)
{
cout << x<<" ";
}

}
cout <<x;

}
return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: