题解 P5712 【【深基3.例4】Apples】

题目传送门

思路

  1. 仔细读题后,我们可以发现,输出可以分成(2)种情况,applesapple不加s,所以我们可以使用if/else来实现。

  2. 接着,我们读入n

	int n;
	cin>>n;
  1. 进行判断,是否需要加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;
}
原文地址:https://www.cnblogs.com/tearing/p/12371894.html