循环单词
2017-10-17 本文已影响0人
風箏嘞
#include <iostream>
using namespace std;
/*
如果一个单词通过循环右移获得的单词,我们称这些单词都为一种循环单词。例如:picture 和 turepic 就是属于同一种循环单词。 现在给出n个单词,需要统计这个n个单词中有多少种循环单词。
输入描述:
输入包括n+1行:
第一行为单词个数n(1 ≤ n ≤ 50)
接下来的n行,每行一个单词word[i],长度length(1 ≤ length ≤ 50)。由小写字母构成
输出描述:
输出循环单词的种数
输入例子1:
5 picture turepic icturep word ordw
输出例子1:
2
*/
int main() {
int n;
cout<<"输入单词个数n"<<endl;
cin>>n;
string word[n];
bool check[n];
for(int i=0; i<n; i++) {
cin>>word[i];
check[i]=false;
}
int res = 0;
//当前循环单词下标
for(int i=0; i<n; i++) {
//挪动次数
for(int j=1; j<word[i].length(); j++) {
char letter=word[i][0];
word[i].assign(word[i],1,word[i].length());
word[i]+=letter;
//相比较单词下标
for(int k=i+1;k<n;k++){
if(word[i].compare(word[k])==0&&!check[i]){
res++;
check[k]=true;
cout<<"i="<<i<<" j="<<j<<" k="<<k<<" the word is = "<<word[i]<<endl;
}
break;
}
}
}
cout<<res<<endl;
return 0;
}