幸运数字 SDUT

幸运数字 SDUT

Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description

我们定义幸运数字为只含有且必须同时含有 4 和 7 的数。例如:47, 747 是幸运数字,而 2333, 666, 457, 777 就不是幸运数字。

现在,bLue 想知道一个数是不是幸运数字,你能帮助他吗?

Input

输入数据有多组(数据组数不超过 100),到 EOF 结束。

每组输入为一行,包含一个非负整数 n,保证 n 在 int 范围内。

Output

对于每组数据,如果输入的数是幸运数字,则输出一行 “Yes”,否则输出一行 “No”(输出内容均不包括引号)。

Sample Input

40
74
747
1047
123

Sample Output

No
Yes
Yes
No
No

Hint
Source

【2016级《程序设计基础(B)I》期末上机考试-第二场】bLue

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int n,i;
int a[1000];
while(~scanf("%d",&n))
{ int top=0; int z=0,x=0,f=0;

  while(n>0)
  {
      a[top++]=n%10;
      n=n/10;

  }
  for(i=0;i<top;i++)                        //注意不是小于等于top啊 //
  {
     if(a[i]==4) z=1;
     else if(a[i]==7) x=1;
     else f++;

  }
  if(x==1&&z==1&&f==0) printf("Yes\n");
  else printf("No\n");

}
return 0;
}

/***************************************************
User name: jk180233李清璇
Result: Accepted
Take time: 0ms
Take Memory: 104KB
Submit time: 2019-01-04 15:13:31
****************************************************/

猜你喜欢

转载自blog.csdn.net/weixin_43892738/article/details/85789064