[問題] lucky number or not

看板C_and_CPP (C/C++)作者 (heymei)時間14年前 (2011/12/06 18:28), 編輯推噓1(1015)
留言16則, 7人參與, 最新討論串1/1
開發平台(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
他是要問nearly lucky number..
12/06 18:34, 1F

12/06 18:51, , 2F
..可不可以在說明卻一點QQ
12/06 18:51, 2F

12/06 18:58, , 3F
你這是問英文不是問程式吧...
12/06 18:58, 3F

12/06 18:58, , 4F
一個數的4和7的總數是4或7, 它就是nearly lucky number
12/06 18:58, 4F

12/06 18:58, , 5F
他說由4和7組成的數字叫lucky number
12/06 18:58, 5F

12/06 18:59, , 6F
.....3F XD
12/06 18:59, 6F

12/06 18:59, , 7F
數字中4和7的總數是lucky number叫nearly lucky number
12/06 18:59, 7F

12/06 19:06, , 8F
找4, 7的個數後加總,可被4 or 7整除即是~
12/06 19:06, 8F

12/06 19:08, , 9F
我看錯了, a大才是對的 :~
12/06 19:08, 9F

12/06 19:20, , 10F
所以要滿足數字全部都是4和7的集合外,還要滿足加起來
12/06 19:20, 10F

12/06 19:20, , 11F
是4 or 7?
12/06 19:20, 11F

12/06 20:17, , 12F
4 7 44 77 47 747這種全由4和7組成的叫lucky
12/06 20:17, 12F

12/06 20:18, , 13F
4477 14477 1238774415477這種4和7的總數是lucky
12/06 20:18, 13F

12/06 20:18, , 14F
的叫nearly lucky
12/06 20:18, 14F

12/06 20:18, , 15F
他要nearly lucky
12/06 20:18, 15F

12/07 08:50, , 16F
第一個 if 就錯了,每一位數都檢查完才能判斷吧?
12/07 08:50, 16F
文章代碼(AID): #1EtUveLr (C_and_CPP)
文章代碼(AID): #1EtUveLr (C_and_CPP)