[問題] lucky number or not
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
C
問題(Question):
Petya loves lucky numbers. We all know that lucky numbers are the positive
integers whose decimal representations contain only the lucky digits 4 and 7.
For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky
if the number of lucky digits in it is a lucky number. He wonders whether
number n is a nearly lucky number.
----------------------------------------------------------------------------
我自己的翻譯是 只要一串數字 裡面 若全部是4與7的組合 則 lucky number
否則不是,但學長說我誤會題意..我看了老半天..都不知道自己哪裡誤會題意..
餵入的資料(Input):
The only line contains an integer n (1≦n≦10^18)
錯誤結果(Wrong Output):
第4筆測試資料沒過= =
程式碼(Code):(請善用置底文網頁, 記得排版)
**由於很短,所以小弟就不po在codepad了**
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
long long int n=0,k=0,temp=0,t=10,i;
scanf("%I64d",&n);
temp = n;
do{
temp = temp/10;
k++;
}while(temp!=0);
for(i=0;i<k;i++)
{
if((n%t)/(t/10)!=4 && (n%t)/(t/10)!=7)
{
printf("NO");
return 0;
}
t=t*10;
}
printf("YES");
return 0;
}
補充說明(Supplement):
Sample test
(1)
input:40047
output:No
(2)
input:7747774
output:YES
(3):10000000000000000
output:No
Note:
In the first sample there are 3 lucky digits (first one and last two), so the
answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the
answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO".
--------------------------------------------------------------------------
我到底題意錯在哪~_~麻煩各位大大惹
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.251.244.130
→
12/06 18:34, , 1F
12/06 18:34, 1F
→
12/06 18:51, , 2F
12/06 18:51, 2F
→
12/06 18:58, , 3F
12/06 18:58, 3F
→
12/06 18:58, , 4F
12/06 18:58, 4F
→
12/06 18:58, , 5F
12/06 18:58, 5F
→
12/06 18:59, , 6F
12/06 18:59, 6F
→
12/06 18:59, , 7F
12/06 18:59, 7F
→
12/06 19:06, , 8F
12/06 19:06, 8F
→
12/06 19:08, , 9F
12/06 19:08, 9F
→
12/06 19:20, , 10F
12/06 19:20, 10F
→
12/06 19:20, , 11F
12/06 19:20, 11F
→
12/06 20:17, , 12F
12/06 20:17, 12F
→
12/06 20:18, , 13F
12/06 20:18, 13F
→
12/06 20:18, , 14F
12/06 20:18, 14F
→
12/06 20:18, , 15F
12/06 20:18, 15F
推
12/07 08:50, , 16F
12/07 08:50, 16F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章
11
37