We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
this is an old discussion but is there any suggestions about this sol in c
/**/
void repeat_char(char c , int co )
{
for (int i=0; i < co; i++ )
{
printf("%c", c);
}
}
int main(){
int t;
scanf("%d",&t);
int n[t];
for(int a0 = 0; a0 < t; a0++){
scanf("%d",&n[a0]);
}
for(int a0 = 0; a0 < t; a0++){
int num5 = n[a0] - n[a0] %3;
int num3 = n[a0] - num5;
switch(num3 % 5){
case 1: num3 = 10;break;
case 2: num3 = 5;break;
case 3: num3 = 15;break;
case 4: num3 = 10;break;
}
if(num3>n[a0]){
printf("-1\n");
continue;
}
num5 = n[a0] - num3;
if(num5>0)
repeat_char('5',num5);
if(num3>0)
repeat_char('3',num3);
printf("\n");
}
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and The Beast
You are viewing a single comment's thread. Return to all comments →
this is an old discussion but is there any suggestions about this sol in c /**/ void repeat_char(char c , int co ) { for (int i=0; i < co; i++ ) { printf("%c", c); } } int main(){ int t; scanf("%d",&t); int n[t]; for(int a0 = 0; a0 < t; a0++){ scanf("%d",&n[a0]); } for(int a0 = 0; a0 < t; a0++){
int num5 = n[a0] - n[a0] %3; int num3 = n[a0] - num5; switch(num3 % 5){ case 1: num3 = 10;break; case 2: num3 = 5;break; case 3: num3 = 15;break; case 4: num3 = 10;break; } if(num3>n[a0]){ printf("-1\n");
continue; } num5 = n[a0] - num3; if(num5>0) repeat_char('5',num5); if(num3>0) repeat_char('3',num3); printf("\n");
}