codeforces 535

A. Tavas and Nafas
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 .

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define maxn 1005
#define inf 0x3f3f3f3f
using namespace std;
char first[11][7]={"zero","one","two","three","four","five","six","seven","eight","nine"};
char second[11][10]={"00","ten","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
char third[11][12]={"00","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
int main()
{
    int n;
    while(cin>>n){
    int a1,a2;
    if(n<=9){
        printf("%s\n",first[n]);
    }
    else if(n==10)printf("%s\n",second[1]);
    else{
        a2=n%10;
        n=n/10;
        a1=n;
        if(a1==1){
            printf("%s\n",third[a2]);
        }
        else if(a2==0)printf("%s\n",second[a1]);
        else
        printf("%s-%s\n",second[a1],first[a2]);
    }
    }
}

B. Tavas and SaDDas
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 477444 are lucky and 517467 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
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#define maxn 100005
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
ll q[maxn];
int main()
{
    int n;
    int t=1;
    ll sum;
    for(int k=0;k<10;k++)                      //二进制枚举
    for(int i=0;i<(1<<k);i++){
        sum=0;
        for(int j=0;j<k;j++){
         sum=sum*10+(i&(1<<j)?4:7);
        }
        q[t++]=sum;
        //cout<<sum<<endl;
    }
    sort(q+1,q+t);
    map<ll,int>mp;
    for(int i=1;i<t;i++){
       mp[q[i]]=i;
   }

    while(cin>>n){
        cout<<mp[n]-1<<endl;
    }

}
dfs更好写,扩展节点的过程刚好就是枚举每个位置的过程。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#define maxn 100005
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
ll q[maxn];
int t;
void dfs(int dep,ll sum){
    q[t++]=sum;
    if(dep>=10)return;
    dfs(dep+1,sum*10+4);
    dfs(dep+1,sum*10+7);
}
int main()
{
    int n;
    t=1;
    dfs(0,0);
    /*for(int i=1;i<t;i++ )
        cout<<q[i]<<" ";
    cout<<endl;*/
    sort(q+1,q+t);
    map<ll,int>mp;
    for(int i=1;i<t;i++){
       mp[q[i]]=i;
   }

    while(cin>>n){
        cout<<mp[n]-1<<endl;
    }
}





1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值