View Code of Problem 3697

#include <cstdio>
#include <string>
#include <iostream>

using namespace std;

string sing(int k){
	string res;
	if(k==1){
		return "1 frog has 1 mouth, 2 eyes and 4 legs, jumps into the water with a splash.";	
	}
	else{
		int mouth=k;
		int eye=k*2;
		int leg=k*4;
		string plash;
		for(int i=0;i<k;i++){
			if(i!=k-1){
				plash+="splash ";
			}
			else{
				plash+="splash.";	
			}
			
		}
//		cout<<plash;
		res+=to_string(k);
		res+=" frogs have ";
		res+=to_string(mouth);
		res+=" mouths, ";
		res+=to_string(eye);
		res+=" eyes and ";
		res+=to_string(leg);
		res+=" legs, jump into the water with ";
		res+=plash;
		return res;
	}
}

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int k,s;
		cin>>k>>s;
		bool flag=true;//默认正常顺序 
		if(k>s)
			flag=false;
		if(flag){
			for(int j=k;j<=s;j++){
				string res=sing(j);
				cout<<res<<endl;
			}	
		}
		else{
			for(int j=k;j>=s;j--){
				string res=sing(j);
				cout<<res<<endl;
			}		
		}
	
	}
}

Double click to view unformatted code.


Back to problem 3697