标签:else main vector clu als sync str with sunday
#include<iostream> #include<cstdio> #include<cmath> #include<string> #include<vector> using namespace std; typedef long long int LL; int Sunday(string text, string pattern){ int i = 0, j = 0, k; int m = pattern.size(); if(pattern.size() <= 0 || text.size() <= 0) return -1; for(; i<text.size();) { if(text[i] != pattern[j]) { for(k=pattern.size() - 1; k>=0; k--) { if(pattern[k] == text[m]) break; } i = m-k; j = 0; m = i+pattern.size(); } else { if(j == pattern.size()-1) return i-j; i++; j++; } } return -1; } vector<string> v; int main() { ios::sync_with_stdio(false); int T; cin>>T; while(T--) { int n; cin>>n; v.clear(); string t,text; for(int i=0;i<n;i++) { cin>>t; if(text.length()<t.length()) text=t; v.push_back(t); } int f=1; for(int i=0;i<n;i++) { if(Sunday(text,v[i])== -1) { f=0; break; } } if(f) cout<<text<<endl; else cout<<"No"<<endl; } return 0; }
2017 ACM-ICPC 亚洲区(青岛赛区)网络赛 1003
标签:else main vector clu als sync str with sunday
原文地址:http://www.cnblogs.com/Roni-i/p/7536338.html