Happy number |
accepted:110 |
|
submit:263 |
Time limit:1000 MS |
|
Memory limit:65536 KB |
Problem Description Recently, Mr Xie learn the concept of happy number. A happy number is a number contain all digit 7 or as 1 digit other than 7. For example, 777 are a happy number because 777 contail all digit 7, 7177 and 87777 both happy number because only 1 digit Other than 7. Whereas 887,799 9807,12345, all of them is not happy number. Now Mr. Xie want to know for a given integer n, how many number among [1,n] is happy numbers, but counting them one by E is slow can I help him? InputFirst line an integer t indicate there is T testcases (1≤t≤100). Then T-lines follow, each line an integer n (1≤n≤106, n don ' t has leading zero). OutputOutput Case number First and then the answer. Sample Input517172030 Sample OutputCase 1:1case 2:7case 3:10case 4:10case 5:11
|
began to dare not to do, fear of violence overtime, later wrote the violence, but the code again problems, day
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include < algorithm>const int N = 1010;using namespace Std;int l=0;int main () {int t,n; scanf ("%d", &t); for (int i = 1;i<=t;i++) {int sum = 0,p = 0,pp = 0,PPP = 0,wz,mo; scanf ("%d", &n); if (n<10) {printf ("Case%d:%d\n", i,n); Continue } else if (n>=10) {wz = 0; Int J; for (j = 10;j<=n;j++) {p = j; pp = 0,PPP = 0; WZ = 0; while (p) {mo = p% 10; wz++; if (mo==7) pp++; else ppp++; if (ppp>=2) break; P/= 10; } if (Ppp==1 && pp==wz-1) sum++; else if (ppp==0 && pp==wz) sum++; } sum + = 9; printf ("Case%d:%d\n", i,sum); }} return 0;}