Thursday, January 4, 2018

UVa problem solution 12592 - Slogan Learning of Princess

problem link:

Discuss: this is simple implementation problem.you can do it with map as well as structure.be careful when taking input. you can use 'getline(cin,string_name)'. and also be careful enough memory declare when use structure else there is run time error.

try yourself,before see the code



#include<bits/stdc++.h>
using namespace std;
struct slogan
{
    string s1,s2,qur;
};
int main()
{
     // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    int n,i,j,cnt=0,flag=0,q;
    string str;
    slogan bullshit[101];
    cin >>n;
    for(i=0;i<n;i++)
    {
        scanf("\n");
     getline(cin,str);
        bullshit[i].s1=str;
   
        str.clear();
        scanf("\n");
      getline(cin,str);
         bullshit[i].s2=str;
   
        str.clear();
    }
    cin >>q;
    for(i=0;i<q;i++)
    {
        scanf("\n");
      getline(cin,str);
        bullshit[i].qur=str;
 
        str.clear();
    }
    for(i=0;i<q;i++)
    {
        for(j=0;j<n;j++)
        {
            if(bullshit[i].qur==bullshit[j].s1)
            {
                cout <<bullshit[j].s2<<endl;
                break;
            }
        }
    }
    return 0;

}

No comments:

Post a Comment