[编程题] 循环单词
2017-08-02 10:26
260 查看
如果一个单词通过循环右移获得的单词,我们称这些单词都为一种循环单词。 例如:picture 和 turepic 就是属于同一种循环单词。 现在给出n个单词,需要统计这个n个单词中有多少种循环单词。
[b]输入描述:[/b]
[b]输入例子1:[/b]
[b]输出例子1:[/b]
通过率为90%,待修改
[b]输入描述:[/b]
输入包括n+1行: 第一行为单词个数n(1 ≤ n ≤ 50) 接下来的n行,每行一个单词word[i],长度length(1 ≤ length ≤ 50)。由小写字母构成[b]输出描述:[/b]
输出循环单词的种数
[b]输入例子1:[/b]
5 picture turepic icturep word ordw
[b]输出例子1:[/b]
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%,待修改
相关文章推荐
- [编程题]循环单词计数
- 牛客网编程题:循环单词(Java实现)
- 2017年校招全国统一模拟笔试(第一场)编程题集合——循环单词
- [编程题] 循环单词
- [编程题] 循环单词
- [编程题]循环单词
- [编程题] 循环单词
- 【网易2017实习生编程题】 工作安排 集合 奇怪的表达式求值 涂棋盘 小易记单词
- 编程在一个已知的字符串中查找最长单词,假定字符串中只含字母和空格,用空格来分隔单词(只使用循环,数组)
- 词组缩写 英语句子所有单词首字母大写输出 C语言/C++编程题
- 【编程之美题目】电话号码对应英语单词(非递归办法控制for循环个数)
- 小易记单词--网易2017春招实习笔试编程题10
- For 循环编程题
- 每天一道编程题——数组元素循环右移问题
- 循环-06. 统计一行文本的单词个数
- 剑指Offer—编程题42(翻转单词顺序)
- 编程题:利用for循环打印 9*9 表?
- 编程题:将一句话里的单词进行倒置
- 循环-06. 统计一行文本的单词个数(15)
- 三个java超级变态逻辑循环编程题