Codeforces Problem-705A Hulk
基本思想:
这是一道小小的思维题,需要循环输出“I hate”和“I love”这两个字符串,在两个字符串间用“that”隔开,最后在输出“it”。
本人的做法是:考虑到“I love”前一定有一个“that”,于是我将“that I love”一起存,只要不是“I hate it”的输出(n=1),在每个“I hate”之前都要加一个“that”,这样就可以得到结果。
AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s1="I hate ";
string s2="that I love ";
int n;
cin>>n;
for (int i=0;i<n;i++)
{
if (i%2==0)
{
if (i!=0)
cout<<"that ";
cout<<s1;
}
else
cout<<s2;
}
cout<<"it"<<endl;
return 0;
}