UVA 12592 Slogan Learning of Princess (Without Map And With Map)




Easy Code (Without Map) 


#include <bits/stdc++.h>
using namespace std;
int main()
{
   int i,j,n,m,k;
   string s,s1,s2,t[1000];
   cin>>n;
   cin.ignore();
   for(i=1;i<=2*n;i++)
   {
      getline(cin,s1);
      t[i]=s1;
   }
   cin>>m;
   cin.ignore();
   for(j=1;j<=m;j++)
   {
       getline(cin,s2);
       for(k=1;k<=2*n;k++)
       {
           if(s2==t[k])
           {
               cout<<t[k+1]<<endl;
           }
       }
   }
   return 0;
}





Using C++ STL Map



#include <bits/stdc++.h>
#include <map>
using namespace std;
int main()
{
   map<string,string>song;
   int i,j,n,m,k;
   string s,s1,s2,t;
   cin>>n;
   cin.ignore();
   for(i=1;i<=n;i++)
   {
      getline(cin,s1);
      getline(cin,s2);
      song.insert(pair<string,string>(s1,s2));

   }
   map<string,string>::iterator p;
   cin>>m;
   cin.ignore();
   for(j=1;j<=m;j++)
   {
       getline(cin,s);
       for(p=song.begin();p!=song.end();p++)
       {
           if(s==p->first)
           {
               cout<<p->second<<endl;
           }
       }


   }
   return 0;
}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment