用c++写In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets. Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem. 输入 The input consists of multiple datasets. Each dataset consists of an integer x in a line. The input ends with an integer 0. You program should not process (print) for this terminal symbol. 输出 For each dataset, print x in the following format: Case i: x where i is the case number which starts with 1. Put a single space between "Case" and i. Also, put a single space between ':' and x.
时间: 2023-06-20 22:10:44 浏览: 378
fatec-uri-online-judge:我所有的URI OJ提交-CC ++
以下是用 C++ 编写的解题代码:
```c++
#include <iostream>
using namespace std;
int main() {
int x, i = 1;
while (cin >> x && x != 0) {
cout << "Case " << i << ": " << x << endl;
i++;
}
return 0;
}
```
这个程序使用了一个 while 循环来不断读入输入数据,直到读入的数据为 0 为止。在循环中,我们输出当前的 case 编号和输入的整数值。需要注意的是,每个 case 编号后面要输出一个冒号和一个空格。
在输出时,我们使用了 `endl` 来输出一个换行符。这样做可以确保每组数据的输出都占用一行,并且在输出结束后换行,方便阅读。
阅读全文