Tuesday 4 July 2017

Uva 11586 - Train Tracks

This is a solution to this Ad Hoc Problem on uva online judge.


Code

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

int main() {
  int t;
  cin >> t;
  cin.ignore();
  while (t--) {
    int m = 0, f = 0;
    string testString;
    getline(cin, testString);
    for (int i = 0; i < testString.length(); i++) {
      if (testString[i] == 'M')
        m++;
      else if (testString[i] == 'F')
        f++;
    }

    if (testString.length < 4)
      cout << "NO LOOP\n";
    else if (m != f)
      cout << "NO LOOP\n";
    else
      cout << "LOOP\n";
  }
}

1 comment:

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

    ReplyDelete