Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- string binary(int x)
- {
- int k; string bin="";
- while(x!=0)
- {
- k=x%2;
- bin+=k+'0';
- x=x/2;
- } //cout<<bin<<endl;
- return bin;
- }
- int main()
- {
- map<string,string>ma;
- ma["one"]="1";
- ma["two"]="2";
- ma["three"]="3";
- ma["four"]="4";
- ma["five"]="5";
- ma["six"]="6";
- ma["seven"]="7";
- ma["eight"]="8";
- ma["nine"]="9";
- ma["ten"]="10";
- ma["eleven"]="11";
- ma["twelve"]="12";
- ma["thirteen"]="13";
- ma["fourteen"]="14";
- ma["fifteen"]="15";
- ma["sixteen"]="16";
- ma["seventeen"]="17";
- ma["eighteen"]="18";
- ma["nineteen"]="19";
- ma["twenty"]="2";
- ma["thirty"]="3";
- ma["forty"]="4";
- ma["fifty"]="5";
- ma["sixty"]="6";
- ma["seventy"]="7";
- ma["eighty"]="8";
- ma["ninety"]="9";
- int t,h=0,th=0,ty=0;
- string s,s1="";
- cin>>t; cin.ignore();
- for(int i=0;i<t;i++)
- {
- getline(cin,s);
- stringstream ss(s);
- string word;
- while(ss>>word)
- {
- s1+=ma[word];
- if(word=="thousand")th=1;
- else if(word=="hundred")h=1;
- if(word=="twenty"||word=="thirty"||word=="forty"||word=="fifty"||word=="sixty"||word=="seventy"||word=="eighty"||word=="ninety")ty=1;
- }
- int l=s1.size();
- if(h==1&&th==0)
- {
- if(l==2&&ty==0)s1.insert(s1.begin()+1,'0');
- if(l==2&&ty==1)s1.insert(s1.end(),'0');
- if(l==1)s1.insert(s1.end(),2,'0');
- }
- else if(th==1)
- {
- if(l==3&&h==1&&ty==1)s1.insert(s1.end(),'0');
- if(l==2&&h==0&&ty==0)s1.insert(s1.begin()+1,2,'0');
- if(l==2&&h==0&&ty==1){s1.insert(s1.begin()+1,'0');s1.insert(s1.end(),'0');}
- if(l==2&&h==1&&ty==0)s1.insert(s1.end(),2,'0');
- if(l==1)s1.insert(s1.end(),3,'0');
- }
- stringstream ss1(s1);
- int x; ss1>>x; //cout<<x<<endl;
- string a,b;
- a=binary(x);
- b=a;
- reverse(a.begin(),a.end());
- if(a==b)cout<<"YES"<<endl;
- else cout<<"NO"<<endl;
- th=ty=h=0;
- s1.clear();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement