思路
仔细读题后,我们可以发现,输出可以分成\(2\)种情况,
apple
加s
与apple
不加s
,所以我们可以使用if/else
来实现。- 接着,我们读入
n
。
int n;
cin>>n;
- 进行判断,是否需要加
s
if(n==1 || n==0) cout<<"Today, I ate "<<n<<" apple.";
else cout<<"Today, I ate "<<n<<" apples.";
参考代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
if(n==1 || n==0) cout<<"Today, I ate "<<n<<" apple.";
else cout<<"Today, I ate "<<n<<" apples.";
return 0;
}