OJ

本文详细记录了作者在尝试使用C++和Python两种编程语言解决ZOJ平台上的1001题时遇到的问题,重点讨论了在不同环境下输出结果的差异,并最终通过调试和理解标准输入格式找到了解决方案。

今天心血来潮试了下几个OJ网站
ZOJ和51nod,试了个最简单的1001题就出了问题

ZOJ Problem Set - 1001A + B Problem


Time Limit: 2 Seconds Memory Limit: 65536 KB


Calculate a + b
Input
The input will consist of a series of pairs of integers a and b,separated by a space, one pair of integers per line.
Output
For each pair of input integers a and b you should output the sum of a and b in one line,and with one line of output for each line in input.
Sample Input
1 5
Sample Output
6
Hint
Use + operator

用C++做了下

#include <iostream>
using namespace std;

int main()
{
    int a, b;
    while (cin >> a >> b)
    {
        cout << a + b << endl;
    }
    return 0;
}

没问题,然后想用python再试下

print sum(map(int, raw_input().split()))

本机测试没问题,提交就出错,看了下zoj给的测试用例,我自己跑却是死循环。又去51nod上试了下,上面的代码没问题AC了,百思不得其解,为啥在ZOJ上总是WRONG,而且他的例子我还跑不起来,然后百度了下,发现是我太low了,
原因是我的代码只输出了第一行的两个数的和。。
而zoj的标准输入里面有好多行的测试数据,51nod估计测试用例也简单
至于zoj的例子是我忘了按Ctrl+Z了。。。

import sys
for line in sys.stdin:
    a = line.split()
    print int(a[0])+int(a[1])

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值