535A Codeforces - Tavas and Nafas


535A Codeforces - Tavas and Nafas






Solution in C++

#include <bits/stdc++.h>

using namespace std;

int n;
string inp,s1,s2;

string cha1(int x)
{
if(x==1)return"one";
else if(x==2)return "two";
else if(x==3)return "three";
else if(x==4)return "four";
else if(x==5)return "five";
else if(x==6)return "six";
else if(x==7)return "seven";
else if(x==8)return "eight";
else if(x==9)return "nine";
else return"-";
}
string cha2(int x)
{
if(x==1)return"ten";
else if(x==2)return "twenty";
else if(x==3)return "thirty";
else if(x==4)return "forty";
else if(x==5)return "fifty";
else if(x==6)return "sixty";
else if(x==7)return "seventy";
else if(x==8)return "eighty";
else if(x==9)return "ninety";
else return"-";
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n;
    if(n==0)return cout<<"zero",0;
    if(n==11)return cout<<"eleven",0;
    if(n==12)return cout<<"twelve",0;
    if(n==13)return cout<<"thirteen",0;
    if(n==14)return cout<<"fourteen",0;
    if(n==15)return cout<<"fifteen",0;
    if(n==16)return cout<<"sixteen",0;
    if(n==17)return cout<<"seventeen",0;
    if(n==18)return cout<<"eighteen",0;
    if(n==19)return cout<<"nineteen",0;
    s1=cha1(n%10);
    s2=cha2(n/10);
         if(s2=="-")cout<<s1;
    else if(s1=="-")cout<<s2;
    else cout<<s2<<"-"<<s1;
    return 0;
}

Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق