Google interView question -1



Q,1) find the array that gave an gold , silver , bronze medel according to their rank

input:[5 ,4 ,3,2,1 ]

output:[ "gold","silver","bronze",4,5]



Solution

 #include<iostream>

#include<algorithm>
#include <bit>
using namespace std;

int main(){
    
    int s[]={5,4,3,2,1};
    int len=sizeof(s)/sizeof(s[0]);
    sort(s ,s+len);
    for(int i=0;i<6;i++){
        if(s[i]==1){
            cout<<"[ ";
            cout<<"gold medal"<<", ";
        }
        else if(s[i]==2){
            cout<<"silver medal"<<",  ";
        }
        else if(s[i]==3){
            cout<<"bronze medal";
        }
        else if(s[i]>3 ){
            string a=to_string(s[i]);
            cout<<" , "<<a;
        }
    
        
    }
    cout<<" ]";
    return 0;    

}

1 Comments

Post a Comment
Previous Post Next Post