點選檢視程式碼
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int> >ans;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin>>T;
while(T--)
{
string s;
cin>>s;
int n=s.size();
if(s[0]=='>'&&s[n-1]=='>'&&s[n-2]=='>'&&s[n-3]=='>'&&s.find('-')!=-1)
{
ans.clear();
int p1,q1,p2=0,q2=0;
while(q2+1<n&&s[q2+1]=='>')
{
q2++;
}
do
{
p1=p2;
q1=q2;
p2=q1+1;
while(s[p2]=='-')
{
p2++;
}
q2=p2;
while(q2+1<n&&s[q2+1]=='>')
{
q2++;
}
for(int i=p1;i<=q1;i++)
{
ans.push_back(make_pair(i,p2+2));
}
}while(q2+1!=n);
for(int i=n-1;i>=p2+2;i--)
{
ans.push_back(make_pair(q1,i));
}
cout<<"Yes"<<" "<<ans.size()<<"\n";
for(int i=0;i<ans.size();i++)
{
cout<<ans[i].first+1<<" "<<ans[i].second-ans[i].first+1<<"\n";
}
}
else
{
cout<<"No"<<"\n";
}
}
return 0;
}