c++ - Codeforces 测试服务器错误,无法在本地机器上重现

标签 c++ c++11 g++

我的代码:

#include <stdlib.h>
#include <iostream>
#include <math.h>

int main(int argc, char *argv[]) {

  long long n = atoi(argv[1]);
  long long m = atoi(argv[2]);
  long long a = atoi(argv[3]);

  if (n == 0 || m == 0 || a == 0) {
    std::cout << "" << 0 << std::endl;
    return 0;
  }

  long long num_tiles = ceil(n / a) * ceil(m / a);

  if (num_tiles == 0) num_tiles = 1;

  std::cout << "" << num_tiles << std::endl;
  return 0;
}

这会在使用 GNU C++ 11 的 Codeforces 测试服务器上产生错误(“测试 1 上的运行时错误”)。我正在使用 g++ -std=c++11 ... 来编译我的本地代码,效果很好。对于所有其他问题解决方案,我也遇到了同样的错误。有什么想法吗?

最佳答案

这些行是罪魁祸首:

int main(int argc, char *argv[]) {
  long long n = atoi(argv[1]);
  long long m = atoi(argv[2]);
  long long a = atoi(argv[3]);

在 Online Judges 中,您必须从标准输入 (STDIN) 获取输入并输出到标准输出 (STDOUT)。

使用任何标准方法,如 scanfcin 获取您的输入并使用 printfcout给出你的输出。不要期望 argcargv 中有任何有用的东西。

看看这个FAQ on Codeforces .

摘自另一名网络评委Codechef ,这也适用于 Codeforces。

If you use any method other than using the standard input and output streams - for example, using command line arguments, reading from a file, opening up some sort of dialog box, or otherwise - you will never be judged correct.

关于c++ - Codeforces 测试服务器错误,无法在本地机器上重现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39968867/

相关文章:

c++ - boost::noncopyable 的 unordered_map 无法从 operator[] 返回引用

c++ - 如何在多线程c++中传递多维数组

c++ - push_backs 到 std::vector<std::reference_wrapper<type>>

c++ - 错误的 "value computed is not used"警告

linux - 我用 g++ 编译时遇到很多错误

gcc - openwrt中的工具链?

c++ - strtod 不会在错误输入时设置 errno

c++ - 使用 std::vector::iterator 更改存储在 std::vector 中的值?

c++ - Boost.Filesystem 如何找出您的可执行文件在哪个目录中?

c++ - 强制程序以 root 身份启动并稍后删除