Sixth session Xiangtan Program design contest-happy number

Source: Internet
Author: User



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?

Input

First 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).

Output

Output Case number First and then the answer.

Sample Input
517172030
Sample Output
Case 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;}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.