[编程题] 循环单词

如果一个单词通过循环右移获得的单词,我们称这些单词都为一种循环单词。 例如: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
#include <iostream>
#include <vector>
#include <string>

using namespace std;

bool Ischild(string str1, string str2)
{
	int j = 0;
	for (int i = 0; i < str1.length(); i++)
	{
		if (str1[i] != str2[j])
		{
			j = 0;
		}
		else 
		{
			j++;
			if (j == str2.length())
				return true;
		}
	}
	return false;
}

bool CompareStr(string str1, string str2)
{
	if (str1.length() != str2.length())
		return false;
	str1 = str1 + str1;
	bool result = false;
	result = Ischild(str1, str2);
	if (result)
		return true;
	return result;

}

int main()
{
	int num;
	vector<string> str;
	vector<int> size;
	cin >> num;
	for (int i = 0; i < num; i++)
	{
		string tmp;
		cin >> tmp;
		str.push_back(tmp);
		size.push_back(0);
	}
	int count = 0;
	
	for (int i = 0; i < num; i++)
	{
		for (int j = i + 1; j < num; j++)
		{
			if (size[i] == 0)
			{
				if (CompareStr(str[i], str[j]))
				{
					size[i] = 1;
					break;
				}
			}
			
		}
		if (size[i] == 0)
			count++;
	}
	cout << count << endl;
	system("pause");
	return 0;
}

通过率为90%,待修改
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值