Search Here

Tuesday, June 30, 2015

UVa - 11586 ( Train Tracks Solution ) [ C & C++ Code ]

Try Yourself First. For help Scroll Down . 

Clearance : Its an easy problem . All you have to do is to Count the ' F ' and ' M ' . If they are same then LOOP else NO LOOP . Now what if the input is "MF" or " FM" ? Find it out yourself. If you found the result then Realize why that Happens ? Compare with Real World.

Code :


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n, m, f;
    scanf("%d",&n);
    getchar();
    while(n--)
    {
        string s;
        getline(cin,s);
        int m = f = 0;
        int len = s.size();
        for(int i=0; i<len; i++)
        {
            if(s[i]=='M')
                m++;
            else if(s[i]=='F')
                f++;
        }
        if(f==m && len>2)
            printf("LOOP\n");
        else
            printf("NO LOOP\n");
    }
    return 0;
}



=> Question or Need Help ?? Leave a Comment .

2 comments:

  1. wrong,,,,FM MF- not loop but yours is loop,,,lack of corner tescase yours is accpeted.

    ReplyDelete
    Replies
    1. There are no lack of corner case. And mine one is OK. Check the link https://ideone.com/W06mGT

      Delete