nano
BAN USERa mixted strategy solution based on the comments before
bool isCount2And3(int A[]){
int *num1 = NULL, *num2 = NULL;
int sum = A[0];
for(int i=1; i<5;++i){
sum+=A[i];
if(!num1) num1=A+i;
if(*num1 == A[i]) continue;
if(!num2) num2=A+i;
if(num2 && *num2!=A[i]) return false;
}
return sum == (*num1)*3+(*num2)*2 || sum == (*num1)*2 + (*num2)*3;
}
a c++ solution
#include <iostream>
#include <unordered_map>
#include <string>
using namespace std;
unordered_map<int,string> num2word_lookup({
{0,""},
{1,"one"},
{2,"two"},
{3,"three"},
{4,"four"},
{5,"five"},
{6,"six"},
{7,"seven"},
{8,"eight"},
{9,"nine"},
{10,"ten"},
{11,"eleven"},
{12,"twelve"},
{13,"thirteen"},
{14,"fourteen"},
{15,"fifteen"},
{16,"sixteen"},
{17,"seventeen"},
{18,"eighteen"},
{19,"ninteen"},
{20,"twenty"},
{30,"thirty"},
{40,"forty"},
{50,"fifity"},
{60,"sixty"},
{70,"seventy"},
{80,"eighty"},
{90,"ninty"},
{100,"hundred"},
{1000,"thousand"},
{1000000,"million"},
{1000000000,"billion"},
{1000000000000,"trilion"}});
string speak3Digit(int n){
string re = "";
int n1=n%10, n2=(n/10)%10, n3=n/100;
if(n2==1)
re=num2word_lookup[n2*10+n1];
else{
re=num2word_lookup[n1];
if(n2!=0)
re=num2word_lookup[n2*10]+" "+re;
}
if(n3)
re=num2word_lookup[n3]+" hundred "+re;
return re;
}
string speakNum(int n){
if(n==0)
return "zero";
string re = "";
bool sign = n>0?true:false;
unsigned int cnt=1,abs_n=n>0?n:-n;
while(abs_n){
re=speak3Digit(abs_n%1000)+(cnt==1?" "+re:" "+num2word_lookup[cnt]+" "+re);
cnt*=1000;
abs_n/=1000;
}
return sign?re:"negative "+re;
}
int main(){
cout<<"0 is "+speakNum(0)<<endl;
cout<<"10234090 is "+speakNum(10234090)<<endl;
return 0;
}
RepLiamLee, abc at ADP
Proven leadership skills that have helped projects get completed within the time and budget constraints, Dedication to following appropriate safety ...
Repmikebeasley033, Interviewer at Brooks Fashions
Working as an interviewer in Brooks Fashion's best amazing experience . Here I manage individuals which makes me refreshed . With ...
RepKoriScott, abc at Omli
Licensed mechanical maintenance engineer with extensive practical experience working with diverse systems and equipment. Solid professional knowledge base built upon ...
Repdubinalinda4, Animator at Apache Design
Hello, I am a school librarian from Lewistown USA. I work in public or private schools at elementary, middle and ...
a c++ solution
- nano April 01, 2015