問題文
A先生正在编写一个程序来处理有关章鱼烧的信息。
该程序处理以下两种输入模式。
模式 1
入力
1 price N
第一行,一个表示模式的整数1。
第二行是每个章鱼烧的价格。price。
第三行,每份章鱼烧的数量N。
出力
章鱼烧每套价格( 输出=N \times price)。
模式 2
入力
2 text price N
第一行,一个表示模式的整数2。
第二行是章鱼烧套餐的描述。text。
第三行是每个章鱼烧的价格。price。
第4行,每份章鱼烧的数量N。
出力
第一行是章鱼烧套餐的描述。
在text结束时
输出为!。
第二行显示一套章鱼烧的价格(=N \times price)。
A先生以为他编写的程序可以如图所示工作,但是当他尝试运行该程序时,出现了错误。
请纠正A编写的程序中的错误,使其正常运行。
A编写的程序
#include <bits/stdc++.h>
using namespace std;
int main() {
int p;
cin >> p;
// パターン1
if (p == 1) {
int price;
cin >> price;
}
// パターン2
if (p == 2) {
string text;
int price;
cin >> text >> price;
}
int N;
cin >> N;
cout << text << "!" << endl;
cout << price * N << endl;
}
即使修改程序的结果是与A先生写的程序有很大差异,只要能AC就可以了。
制約
- 0≦price, N≦100
- price, N是一个整数
- text由半角字母数字字符组成
- text小于 20 个字符
Judge 还测试以下输入示例以外的情况。注意。
入力例1
1 80 5
出力例1
400
入力例2
2 umai 150 3
出力例2
umai! 450
入力例3
2 good! 30 8
出力例3
good!! 240
测试输入/输出
只有当你写的程序没有变成AC并且你找不到原因时,请看这个。
单击查看测试输入/输出
测试输入 1
1 2 3
测试输出 1
6
测试输入 2
2 yeah!...!ok 100 100
测试输出 2
yeah!...!ok! 10000
解答例
观看前请务必亲自尝试一下问题。
点击查看示例答案
#include <bits/stdc++.h>
using namespace std;
int main() {
int p;
cin >> p;
// パターン2
if (p == 2) {
string text;
cin >> text;
cout << text << "!" << endl;
}
int price, N;
cin >> price >> N;
cout << price * N << endl;
}