《ASCE1885的ACM解题报告》のzoj1001

ACM竞赛中,在将编制好的程序提交到在线评测系统(Online Judge)之前,必须在本机上调试通过。

在本机调试的方法比较讲究,一般是从一个文本文件,如“asce.txt”中读入数据,再输出数据到屏幕上即可。下面来看一下zoj1001问题A+B problem

===============================================

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

 

===============================================

Dev-C++4.9.9.2中新建一个app文件,敲入下面代码:(其中asce.txt文件和app文件在同一目录下面)

#include <fstream>

#include<iostream>

int main()

{

    //输入设备改为文本文件asce.txt

    std::ifstream cin("asce.txt");

    int a, b;

    //从输入设备读取两个整数

    while(cin>>a>>b)

    {

        std::cout<<a+b<<std::endl;  

    }                             

    system("pause");

    return 0;

}

 

上面程序运行时,会从asce.txt文件中读入数据,注意输入对象cin不应该加std::前缀,因为这是我们重定义了的。cin在读入数据时,会忽略空格和回车符。

 

当然额,上面的代码是我们在本机调试时使用的,当调试完成需要提交到Online Judge上面时,我们需要修改代码如下:

#include<iostream>

int main()

{

    int a, b;

    //从输入设备读取两个整数

    while(std::cin>>a>>b)

    {

        std::cout<<a+b<<std::endl;  

    }                             

    return 0;

}

 

代码提交后,Judge Status(评测状态)一般有以下几种情况:

Accepted:恭喜,通过;

Presentation Error:输出格式错误;

Wrong Answer:答案错误;

Runtime Error:程序运行时发生错误,多为数组访问越界;

Time Limit Exceeded:超时错误,程序运行时间超过限制的时间;

Memory Limit Exceeded:超内存错误,程序运行使用的内存超过限制的内存用量;

Compile Error:编译错误,源代码中有语法错误。

 

 

posted on 2010-08-30 15:24  android开发实例  阅读(191)  评论(0编辑  收藏  举报

导航