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.
The first and only line of input contains an integer s (0 ≤ s ≤ 99), Tavas's score.
In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces.
6
six
99
ninety-nine
20
twenty
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]);
}
}
}
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 n. Lucky 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.
The first and only line of input contains a lucky number n (1 ≤ n ≤ 109).
Print the index of n among all lucky numbers.
4
1
7
2
77
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