65,211
社区成员
发帖
与我相关
我的任务
分享
string lyric(int);
void printLyrics(int);
int main()
{
for (int i=1;i <=6;i++)
{
printLyrics(i);
}
return 0;
}
string lyric(int n)
{
string ly;
if(n==1)
ly ="B-I-N-G-O!";
else if(n==6)
{
ly = lyric(n-1);
int position = ly.find(")");
ly = ly.replace(position,4,",clap)");
}
else
{
string preLyric = lyric(n-1);
int position = ly.find(")");
ly = ly.replace(position,3,",clap)");
}
return ly;
}
void printLyrics(int n)
{
cout <<"There was a farmer had a dog," <<endl;
cout <<" And Bingo was his name-o." <<endl;
cout <<" " <<lyric(n) <<endl;
cout <<" " <<lyric(n) <<endl;
cout <<" " <<lyric(n) <<endl;
cout <<"And Bingo was his name-o!" <<endl;
cout <<endl;
}
#include <iostream>
#include <string>
using namespace std;
string lyric(int);
void printLyrics(int);
int main()
{
for (int i = 1; i <= 6; i++)
{
printLyrics(i);
}
return 0;
}
string lyricFunc(int n)
{
string lyric;
if (n == 1)
lyric = "B-I-N-G-O!";
else if (n == 6)
{
string preLyric = lyricFunc(n - 1);
int position = preLyric.find(")");
if (position != -1)
{
lyric = preLyric.replace(position, 4, ",clap)");
}
}
else
{
string preLyric = lyricFunc(n - 1);
int position = preLyric.find(")");
if (position != -1)
{
lyric = preLyric.replace(position, 3, ",clap)");
}
}
return lyric;
}
void printLyrics(int n)
{
cout << "There was a farmer had a dog," << endl;
cout << " And Bingo was his name-o." << endl;
cout << " " << lyricFunc(n) << endl;
cout << " " << lyricFunc(n) << endl;
cout << " " << lyricFunc(n) << endl;
cout << "And Bingo was his name-o!" << endl;
cout << endl;
}