搜狐畅游游戏开发编程题
搜狐畅游游戏开发编程题
搜狐畅游两道编程题
1 最短距离
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
int x, y, n;
char ch;
string str;
cin >> x >>ch>> y>>ch >> n>>ch;
int min = 9999999;
int res_x = 0, res_y = 0;
int value = 0;
vector<int> arr(n*2, 0);
for (int i = 0; i < n*2; i+=2)
{
int a, b;
char c;
cin >> a >> c >> b;
arr[i] = a;
arr[i + 1] = b;
if (i != 2*n - 2)
cin >> c;
}
for (int i = 0; i < 2 * n; i+=2)
{
value = (arr[i] - x)* (arr[i] - x) + (arr[i+1] - y)* (arr[i+1] - y);
if (value < min)
{
min = value;
res_x = arr[i];
res_y = arr[i + 1];
}
}
cout << "(" << res_x << "," << res_y << ")" << endl;
system("pause");
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
int x, y, n;
char ch;
string str;
cin >> x >>ch>> y>>ch >> n>>ch;
int min = 9999999;
int res_x = 0, res_y = 0;
int value = 0;
vector<int> arr(n*2, 0);
for (int i = 0; i < n*2; i+=2)
{
int a, b;
char c;
cin >> a >> c >> b;
arr[i] = a;
arr[i + 1] = b;
if (i != 2*n - 2)
cin >> c;
}
for (int i = 0; i < 2 * n; i+=2)
{
value = (arr[i] - x)* (arr[i] - x) + (arr[i+1] - y)* (arr[i+1] - y);
if (value < min)
{
min = value;
res_x = arr[i];
res_y = arr[i + 1];
}
}
cout << "(" << res_x << "," << res_y << ")" << endl;
system("pause");
2.求第k个数
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n, k;
while (cin >> n >> k)
{
long long sum = 0;
int tmp = k;
int i = 0;
while (tmp)
{
if (tmp & 1 == 1)
{
sum += pow(n, i);
}
i++;
tmp >>= 1;
}
cout << sum << endl;
}
}
#笔试题目##搜狐畅游##include<algorithm>
using namespace std;
int main()
{
int n, k;
while (cin >> n >> k)
{
long long sum = 0;
int tmp = k;
int i = 0;
while (tmp)
{
if (tmp & 1 == 1)
{
sum += pow(n, i);
}
i++;
tmp >>= 1;
}
cout << sum << endl;
}
}