Thursday, June 2, 2016

13026-Search the Khoj-solution hints

https://uva.onlinejudge.org/external/130/13026.pdf

After all it's an easy ad-hoc problem . Just think deeply then i guess you can solve it easily .

I have here solve this problem using string but you can complete using other means . Here's nothing but only one logic which is ,

1. It is said that jalil can mistake just one letter that means if any string matches (length-1) times with the mummy's phone number then that is answer  . Similar all the numbers will be the answer .

My accepted code is given below :

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t,i=1,num,l,s;
    string n[1002];

    scanf("%d",&t);

    while(t>=i)
    {

        scanf("%d",&num);

        for(int j=1;j<=num+1;j++)
        {
            cin>>n[j];
        }

        l=n[num+1].length();

        printf("Case %d:\n",i);

        for(int j=1;j<=num;j++)
        {
            s=0;

            for(int k=0;k<l;k++)
            {
                if(n[num+1][k]==n[j][k])
                {
                    s++;
                }
            }

            if((s+1)==l || s==l)
            {
                cout<<n[j]<<endl;
            }

        }

        i++;
    }

    return 0;

}


No comments:

Post a Comment