这个cpp代码在没有主函数的情况下是如何运行的
how is this cpp code running without a main function?
zig_zag 提交的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);
}
};
toporder runner需要一个具有特定方法接口的类,它在问题语句中指定。对于这个特定的问题,它就在这里。
Topcoder将使用额外的源代码编译此代码,这是一个主要的方法,它运行示例。
如果你想在toporder编辑器中本地测试你的代码(或者只是自动生成运行它的代码),有几个插件可以使用,例如ExampleBuilder。
这只是一个带有类定义的.cpp文件。main()函数位于项目中的其他位置。
相关文章:
- 运行同一解决方案的另一个项目的项目
- CMake-按正确顺序将项目与C运行时对象文件链接
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- 代码在main()中运行,但在函数中出现错误
- 我在c++代码中生成了一个运行时#3异常
- 如何在linux终端中同时编译和运行c++代码
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 如何在运行中期切换GTK CSS style_context
- 如何在MS Visual Studio 2019中运行QT UI
- 如何通过cpp程序运行shell脚本
- IPC使用多个管道和分支进程来运行Python程序
- 删除指向指针的指针是运行时错误吗
- 如何用参数值调用函数(仅在运行时已知)
- 为什么即使使用-cudart-static进行编译,库用户仍然需要链接到cuda运行时
- 是否可以在编译时初始化数组,以便在运行时不会花费时间?
- c++中的指针和运行时错误
- 在C应用程序中运行C++(带有STL)函数
- 运行程序时出现问题
- 控制允许动态运行c++的并发操作数
- 无法获取菜单选择以运行函数.C++