【发布时间】:2016-07-21 07:15:06
【问题描述】:
zig_zag提交的topcoder问题BearNSWE
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <string>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
double xx, yy;
class BearNSWE
{
public:
double totalDistance(vector <int> a, string dir)//no main function
{
int n = a.size();
double ans = 0.0;
xx = yy = 0.0;
for (int i = 0; i < n; i++)
{
if (dir[i] == 'N')
{
yy = yy + a[i];
}
else if (dir[i] == 'S')
{
yy = yy - a[i];
}
else if (dir[i] == 'W')
{
xx = xx - a[i];
}
else if (dir[i] == 'E')
{
xx = xx + a[i];
}
ans = ans + a[i];
}
return ans + sqrt(xx*xx + yy*yy);
}
};
【问题讨论】:
-
你编译并链接它看它是否运行?