#28594: CPP


11030067@mail.hpsh.tp.edu.tw (和平110級鄧雨珊)

學校 : 臺北市立和平高級中學
編號 : 163096
來源 : [61.64.210.174]
最後登入時間 :
2022-10-23 16:54:59
d275. 11586 - Train Tracks -- UVa11586 | From: [203.72.60.244] | 發表日期 : 2021-12-20 11:55

#include <iostream>
#include <sstream>
using namespace std;

int main() {
int t;
string s;
char head, tail, pre;
cin >> t;
getline(cin, s);
while (t--){
bool loop=true;
int len=1;
getline(cin, s);
head=s[0];
tail=s[s.size()-1];
if (head==tail){
cout <<"NO LOOP\n";
continue;
}
stringstream ss(s);
string x;
ss >> x;
pre=x[1];
while (ss >> x){
len++;
if (pre==x[0]){
loop=false;
break;
}
pre=x[1];
}
if (len>1 && loop){
cout <<"LOOP\n";
}
else {
cout <<"NO LOOP\n";
}
}
}
 
ZeroJudge Forum