aaah

aaah

时间: 1ms        内存:128M

描述:

Jon Marius shouted too much at the recent Justin Bieber concert, and now needs to go to the doctor because of his sore throat. The doctor’s instructions are to say “aaah”. Unfortunately, the doctors sometimes need Jon Marius to say “aaah” for a while, which Jon Marius has never been good at. Each doctor requires a certain level of “aah” – some require “aaaaaah”, while others can actually diagnose his throat with just a “h”. (They often diagnose wrongly, but that is beyond the scope of this problem.) Since Jon Marius does not want to go to a doctor and have his time wasted, he wants to compare how long he manages to hold the “aaah” with the doctor’s requirements. (After all, who wants to be all like “aaah” when the doctor wants you to go “aaaaaah”?)
Each day Jon Marius calls up a different doctor and asks them how long his “aaah” has to be. Find out if Jon Marius would waste his time going to the given doctor.

输入:

The input consists of two lines. The first line is the “aaah” Jon Marius is able to say that day. The second line is the “aah” the doctor wants to hear. Only lowercase ’a’ and ’h’ will be used in the input, and each line will contain between 0  and 999  ’a’s, inclusive, followed by a single ’h’.

输出:

Output “go” if Jon Marius can go to that doctor, and output “no” otherwise.

示例输入:

aaah
aaaaah

示例输出:

no

提示:

参考答案(内存最优[748]):

#include<stdio.h>
int main()
{
	char m,n;
	int b=0,a=0,c=0,d,e;
	while(scanf("%c",&n)!=EOF)
	{
	  if(n=='a') b+=1;
	  
	  if(n=='h') 
	  {e=d;
		  d=b;
	  ;
	  b=0;
		  c=c+1;
	}
	  
	  if(c==2) 
	  {
         if(e>=d) printf("go\n");
	     else printf("no\n");
		 b=0;a=0;
		 c=0;

	  }
	}
	  return 0;

}

参考答案(时间最优[0]):

#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	char can[1000];
	char need[1000];
	while(cin>>can>>need)
	{
		if(strlen(can)<strlen(need)) cout<<"no"<<endl;
		else cout<<"go"<<endl;
	}
	return 0;
}

题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注