Codeforces Round #299 (Div. 2)

          A. Tavas and Nafas
 
 

Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.

His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words.

He ate coffee mix without water again, so right now he's really messed up and can't think.

Your task is to help him by telling him what to type.

Input

The first and only line of input contains an integer s (0 ≤ s ≤ 99), Tavas's score.

Output

In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces.

Sample test(s)
input
6
output
six
input
99
output
ninety-nine
input
20
output
twenty
Note

You can find all you need to know about English numerals in http://en.wikipedia.org/wiki/English_numerals .

题意:输入n (0<=n<=99)

   输出对应的英语(基数词)

 1 #include<iostream>
 2 using namespace std;
 3 
 4 void output(int x)
 5 {
 6     if(x==0)
 7         cout<<"zero";
 8     else if(x==1)
 9         cout<<"one";
10     else if(x==2)
11         cout<<"two";
12     else if(x==3)
13         cout<<"three";
14     else if(x==4)
15         cout<<"four";
16     else if(x==5)
17     //比赛的时候这里写成了cout<"five";
18     //所以这道题没有过,掉了91分
19     //也没有什么好说的,错就是错了
20         cout<<"five";
21     else if(x==6)
22         cout<<"six";
23     else if(x==7)
24         cout<<"seven";
25     else if(x==8)
26         cout<<"eight";
27     else if(x==9)
28         cout<<"nine";
29     else if(x==10)
30         cout<<"ten";
31     else if(x==11)
32         cout<<"eleven";
33     else if(x==12)
34         cout<<"twelve";
35     else if(x==13)
36         cout<<"thirteen";
37     else if(x==14)
38         cout<<"fourteen";
39     else if(x==15)
40         cout<<"fifteen";
41     else if(x==16)
42         cout<<"sixteen";
43     else if(x==17)
44         cout<<"seventeen";
45     else if(x==18)
46         cout<<"eighteen";
47     else if(x==19)
48         cout<<"nineteen";
49     else if(x==20)
50         cout<<"twenty";
51     else if(x==30)
52         cout<<"thirty";
53     else if(x==40)
54         cout<<"forty";
55     else if(x==50)
56         cout<<"fifty";
57     else if(x==60)
58         cout<<"sixty";
59     else if(x==70)
60         cout<<"seventy";
61     else if(x==80)
62         cout<<"eighty";
63     else if(x==90)
64         cout<<"ninety";
65 }
66 int main()
67 {
68     int n;
69     while(cin>>n)
70     {
71         if(n<=20)
72         {
73             output(n);
74             cout<<endl;
75         }
76         else
77         {
78             int a=n%10;
79             int b=(n/10)*10;
80             if(a==0)
81             {
82                 output(b);
83                 cout<<endl;
84             }
85             else{
86                 output(b);
87                 cout<<"-";
88                 output(a);
89                 cout<<endl;
90             }
91         }
92     }
93     return 0;
94 }
View Code
        B. Tavas and SaDDas
 

Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."

The problem is:

You are given a lucky number nLucky 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.

If we sort all lucky numbers in increasing order, what's the 1-based index of n?

Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.

Input

The first and only line of input contains a lucky number n (1 ≤ n ≤ 109).

Output

Print the index of n among all lucky numbers.

Sample test(s)
input
4
output
1
input
7
output
2
input
77
output
6

题意:lucky number是指只由4,7组成的数字,

   现在将这些数字按小到大排序

   输入n  (n为lucky number,问排序后n是在第几,从1开始算)

    

思路:k位数的lucky number 有2^k个

   若n为k位数,则n排在2^1~2^(k-1) 后面,然后再算n在k位数中排在第几。

   

 1 #include<iostream>
 2 #include<cstring>
 3 using namespace std;
 4 int a[15];
 5 int main()
 6 {
 7     a[0]=1;
 8     for(int i=1;i<=9;i++)
 9         a[i]=a[i-1]*2;
10     char s[15];
11     while(cin>>s)
12     {
13         int len=strlen(s);
14         int sum=a[len];
15         int cnt=0;
16         for(int i=0;i<len;i++)
17         {
18             if(s[i]=='4')
19             {
20                 sum=sum/2;
21             }
22             else{
23                 cnt+=sum/2;
24                 sum=a[len-i-1];
25             }
26         }
27         sum+=cnt;
28         for(int i=1;i<len;i++)
29             sum+=a[i];
30         cout<<sum<<endl;
31     }
32     return 0;
33 }
View Code
原文地址:https://www.cnblogs.com/-maybe/p/4428130.html