Happy Number

Problem Description

Recently, Mr. Xie learn the concept of happy number. A happy number is a number contain all digit 7 or only 1 digit other than 7. For example, 777 is 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 are not happy number. Now Mr. xie want to know for a given integer n, how many number among [1,n] are happy numbers, but counting them one by one is slow, can you help him?

Input

First line an integer t indicate there are t testcases(1≤t≤100). Then t lines follow, each line an integer n(1≤n≤106, n don't have leading zero).

Output

Output case number first, then the answer.

Sample Input
5
1
7
17
20
30
Sample Output
Case 1: 1
Case 2: 7
Case 3: 10
Case 4: 10

Case 5: 11

//题解:将1 --- 1000000的数全部打表出来。

//标程:

#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;

int main()
{
 //	freopen("a.txt","r",stdin);
	int t, n, i, j;
	int p[200] = {1,2,3,4,5,6,7,8,9,17,27,37,47,57,67,70,71,72,
		          73,74,75,76,77,78,79,87,97,177,277,377,477,577,
				  677,707,717,727,737,747,757,767,770,771,772,773,
				  774,775,776,777,778,779,787,797,877,977,1777,2777,
				  3777,4777,5777,6777,7077,7177,7277,7377,7477,7577,7677,
				  7707,7717,7727,7737,7747,7757,7767,7770,7771,7772,7773,7774,
				  7775,7776,7777,7778,7779,7787,7797,7877,7977,8777,9777,17777,
				  27777,37777,47777,57777,67777,70777,71777,72777,73777,74777,75777,
				  76777,77077,77177,77277,77377,77477,77577,77677,77707,77717,77727,
				  77737,77747,77757,77767,77770,77771,77772,77773,77774,77775,77776,
				  77777,77778,77779,77787,77797,77877,77977,78777,79777,87777,97777,
				  177777,277777,377777,477777,577777,677777,707777,717777,727777,737777,
				  747777,757777,767777,770777,771777,772777,773777,774777,775777,776777,
				  777077,777177,777277,777377,777477,777577,777677,777707,777717,777727,
				  777737,777747,777757,777767,777770,777771,777772,777773,777774,777775,
				  777776,777777,777778,777779,777787,777797,777877,777977,778777,779777,
				  787777,797777,877777,977777};
	cin >> t;
    for(i = 1; i <= t; ++ i)
	{
        cin >> n;
		for(j = 0; p[j] <= n && j < 189; ++ j);
		printf("Case %d: %d\n",i,j);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
(Telephone Number Word Generator) Standard telephone keypads contain the digits 0 through 9. The numbers 2 through 9 each have three letters associated with them, as is indicated by the following table: Many people find it difficult to memorize phone numbers, so they use the correspondence between digits and letters to develop seven-letter words that correspond to their phone numbers. For example, a person whose telephone number is 686-2377 might use the correspondence indi- cated in the above table to develop the seven-letter word “NUMBERS.” Businesses frequently attempt to get telephone numbers that are easy for their clients to remember. If a business can advertise a simple word for its customers to dial, then no doubt the business will receive a few more calls. Each seven-letter word corresponds to exactly one seven-digit telephone number. The restaurant wishing to increase its take-home business could surely do so with the number 825-3688 (i.e., “TAKEOUT”). Each seven-digit phone number corresponds to many separate seven-letter words. Unfortunately, most of these represent unrecognizable juxtaposi- tions of letters. It’s possible, however, that the owner of a barber shop would be pleased to know that the shop’s telephone number, 424-7288, corresponds to “HAIRCUT.” A veterinarian with the phone number 738-2273 would be happy to know that the number corresponds to “PETCARE.” Write a program that, given a seven-digit number, writes to a file every possible seven-letter word corresponding to that number. There are 2187 (3 to the seventh power) such words. Avoid phone numbers with the digits 0 and 1.
最新发布
06-09

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值