关于c++一个简单的问题

来源:百度知道 编辑:UC知道 时间:2024/07/05 23:22:45
首先是按下面的格式输入
2 3
4 8
2 3
...
但不知道要输入多少组
现在就是要判断她什么时候结束。
其实这是一个题:
要求是按上面的格式输入,并返回两数和。
但如果不判断输入结束程序就不能完结。
#include<iostream.h>
void main()
{
int a,b;
whlie(cin>>a>>b)

{cout<<a+b<<endl;}
}
要按上的格式输入,不能有其他的符号出现,
这是个OJ上的题
我也没办法,谢谢大家
这是ACM上的题,但是我自己简化了的。主要是想解决输入问题。小弟英语不太好,嘿嘿~~
原题如下:
Description

Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems.

This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 25.
Input

The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in c

又是ACM?你可以把题目发上来,上面应该会有提示,比如总共输入多少组数据之类的。
你还是把全部原题发上来吧,没准你漏掉一个重要的提示。至少从你现在发的我看不出来有任何提示。

嗯~~windows系统下我们通过键入ctrl+z来输入文件结束符,Unix中用ctrl+d。主要就是针对这种while(cin>>x)的,虽然有时也可以通过输入与x不同的类型数据导致出错来结束程序,不过正规的还是输入文件结束符哈

The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9.

这个跟你说的不一样啊。。按他的意思。。不是应该是
12.345 25 这种样子吗。。前6列是R,后两列是n,怎么变你说的那样了,而且只要输入一行就可以了吧

你可以指定一个结束符,比如 # 号,然后
if(a == '#')break;