Unlucky Number I
来源:互联网 发布:淘宝羊毛衫 编辑:程序博客网 时间:2024/06/13 13:57
Unlucky Number I
Description
思路1:用字符串,如果4或者7出现的次数等于字符串的长度,就是YES!
代码:
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
int t;
while(~scanf("%d",&t))
{
while(t--)
{
int flag=0;
char a[20];
scanf("%s",a);
int l=strlen(a);
for(int i=0;i<l;i++)
{
if(a[i]=='4'||a[i]=='7')
{
flag++;
}
}
if(flag==l)
{
printf("YES\n");
}
else printf("NO\n");
}
}
return 0;
}
思路2:如果哪一位数字既不是4也不是7就输出NO,否则·输出YES。
代码:
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
int t;
while(~scanf("%d",&t))
{
while(t--)
{
int flag=0;
char a[20];
scanf("%s",a);
int l=strlen(a);
for(int i=0;i<l;i++)
{
if(a[i]!='4'&&a[i]!='7') //这里我刚开始用了或,导致出错@~@,尴尬了,哈哈。。
{
flag=1;
break;
}
}
if(flag==1)
{
printf("NO\n");
}
else printf("YES\n");
}
}
return 0;
}
Some positive integers’ representationsonly consist of the unlucky digits 4 and 7. We call them Unlucky Numbers. Forexample, numbers 74, 774, 7 are unlucky while 2, 12, 352 are not.
Please determine whether a given n is an unlucky number.
InputThere are multiple test cases. Thefirst line of input is an integerT indicating the number of test cases. ThenT test cases follow.
For each test case:
Line 1. This line contains an integer n (1 ≤n ≤ 109).
OutputFor each test case:
Line 1. Output "YES" if thegiven n is an unlucky number,otherwise output "NO" instead.
Sample Input2
47747
12347
Sample OutputYES
NO
题意:仅有4或者7就输出YES,否则输出NO。思路1:用字符串,如果4或者7出现的次数等于字符串的长度,就是YES!
代码:
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
int t;
while(~scanf("%d",&t))
{
while(t--)
{
int flag=0;
char a[20];
scanf("%s",a);
int l=strlen(a);
for(int i=0;i<l;i++)
{
if(a[i]=='4'||a[i]=='7')
{
flag++;
}
}
if(flag==l)
{
printf("YES\n");
}
else printf("NO\n");
}
}
return 0;
}
思路2:如果哪一位数字既不是4也不是7就输出NO,否则·输出YES。
代码:
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
int t;
while(~scanf("%d",&t))
{
while(t--)
{
int flag=0;
char a[20];
scanf("%s",a);
int l=strlen(a);
for(int i=0;i<l;i++)
{
if(a[i]!='4'&&a[i]!='7') //这里我刚开始用了或,导致出错@~@,尴尬了,哈哈。。
{
flag=1;
break;
}
}
if(flag==1)
{
printf("NO\n");
}
else printf("YES\n");
}
}
return 0;
}
0 0
- Unlucky Number I
- unlucky number
- nyoj 1172 unlucky number
- nyist oj 1172 unlucky number
- NYOJ---题目1172unlucky number
- nyoj unlucky number 1184 (**打表**)
- I-number
- I-number
- I - I-number
- hdu4608 - I-number(水题)
- HDU4608 I-number
- HDU4608:I-number
- hust I-number题解
- hdu 4608 I-number
- hdu 4608 I-number
- hdu 4608 I-number
- Single Number I & II
- HDU4608:I-number
- Android枚举类引用实例
- 最长公共子串
- 文章标题
- SharedPreferences
- hrbust/哈理工oj 1334 最好的心情【求最长递增子序列&&最大值】
- Unlucky Number I
- PS基础知识二
- ML_Liner Regression[机器学习]
- 开始学习HANA: In-memory Computing with SAP HANA on Lenovo X6 Systems
- linux 下查看系统资源和负载,以及性能监控
- leetcode_c++:3Sum Closest(016)
- Windows 08R2_破解管理员密码
- Hue-安装-配置-添加Oozie
- 【LeetCode】113. Path Sum II 基于Java和C++的解法及分析