A. Hongcow Learns the Cyclic Shift #385
2016-12-21 09:42
267 查看
A. Hongcow Learns the Cyclic Shift
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic
shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on.
Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted.
Input
The first line of input will be a single string s (1 ≤ |s| ≤ 50),
the word Hongcow initially learns how to spell. The string s consists only of lowercase English letters ('a'–'z').
Output
Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.
Examples
input
output
input
output
input
output
Note
For the first sample, the strings Hongcow can generate are "abcd", "dabc",
"cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".
原题链接http://codeforces.com/contest/745/problem/A
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic
shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on.
Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted.
Input
The first line of input will be a single string s (1 ≤ |s| ≤ 50),
the word Hongcow initially learns how to spell. The string s consists only of lowercase English letters ('a'–'z').
Output
Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.
Examples
input
abcd
output
4
input
bbb
output
1
input
yzyz
output
2
Note
For the first sample, the strings Hongcow can generate are "abcd", "dabc",
"cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".
原题链接http://codeforces.com/contest/745/problem/A
/* _...---.._ ,' ~~"--.. / ~"-._ / ~-. / . `-. \ -.\ `-. \ ~-. `-. ,-~~\ ~. / \ `. . \ `. | \ . | \ \ . `. \ \ \ ` `. \ ` \. \ ` \`. \ . \ -. \ ` -. \ . ` - \ . ` \ ~- \ ` . ~. \ . \ -_ \ ` - \ . | ~. \ ` | \ \ . | \ \ ` | `. \ 1344c ` ` \ \ . . `. `. ` : \ `. \ ` \ `. \ . `. `~~-. \ : ` \ \ . . \ : `.\ ` : \ | | . \ . \ | | \ : \ ` | ` . . | |_ . ` `. ` ` | ~.; \ `. . . . . `. ` ` ` `. `._. \ `.\ ` < \ `. | . ` ` : ` | | ` \ ` | | `. | \ : .' | "Are you crying? " ` | \ `_-' | "It's only the rain." : | | | : ; "The rain already stopped."` ; |~-.| : ' "Devils never cry." : \ | ` , ` \` : ' : \` `_/ ` .\ "For we have none. Our enemy shall fall." ` ` \ "As we apprise. To claim our fate." \ | : "Now and forever. " \ .' : "We'll be together." : : "In love and in hate" | .' | : "They will see. We'll fight until eternity. " | ' "Come with me.We'll stand and fight together." | / "Through our strength We'll make a better day. " `_.' "Tomorrow we shall never surrender." sao xin*/ #include <bits/stdc++.h> using namespace std; #define LL long long #define INF 0x3f3f3f3 #define pi acos(-1) //const LL INF = 1e15; const int maxn=1e3+5; const int maxx=1e5+5; //const double q = (1 + sqrt(5.0)) / 2.0; // 黄金分割数 /* std::hex <<16进制 cin>>std::hex>>a>>std::hex>>b cout.setf(ios::uppercase);cout<<std::hex<<c<<endl; //f[i]=(i-1)*(f[i-1]+f[i-2]); 错排 priority_queue<int,vector<int>,greater<int> >que3;//注意“>>”会被认为错误, priority_queue<int,vector<int>,less<int> >que4;////最大值优先 //str tmp vis val cnt 2486 struct point { int id; int ed; bool operator < (const point &a) const { return ed > a.ed;//结束时间早的优先级高 } } p; */ string in; set<string> s; int main() { while(cin>>in) { int len = in.length(); for(int i=0;i<len;i++) { in += in[i]; } for(int i=0;i<len;i++) { string tmp; for(int j=0;j<len;j++) { tmp += in[i+j]; } //cout<<tmp<<endl; s.insert(tmp); } cout<<s.size()<<endl; } return 0; } string的应用 也可以用len的因子 比如4-2-1 因为如果要重复出现的话,必然是有重复单元,这里给出思路,人懒没写代码
相关文章推荐
- A. Hongcow Learns the Cyclic Shift #385
- A. Hongcow Learns the Cyclic Shift #385
- A. Hongcow Learns the Cyclic Shift #385
- A. Hongcow Learns the Cyclic Shift #385
- A. Hongcow Learns the Cyclic Shift #385
- A. Hongcow Learns the Cyclic Shift #385
- A. Hongcow Learns the Cyclic Shift #385
- A. Hongcow Learns the Cyclic Shift #385
- A. Hongcow Learns the Cyclic Shift #385
- A. Hongcow Learns the Cyclic Shift #385
- A. Hongcow Learns the Cyclic Shift #385
- Hongcow Learns the Cyclic Shift CodeForces - 745A
- 【67.24%】【codeforces 745A】Hongcow Learns the Cyclic Shift
- Codeforces Round #385 (Div. 2)A.Hongcow Learns the Cyclic Shift【暴力】水题
- cf Hongcow Learns the Cyclic Shift
- Codeforces Round #385 (Div. 2) A. Hongcow Learns the Cyclic Shift 水题
- 745 A. Hongcow Learns the Cyclic Shift codeforces
- A. Hongcow Learns the Cyclic Shift
- Codeforces Round #385 (Div. 2)C. Hongcow Builds A Nation【并查集+贪心】好题~
- ZJNU 1901 Why Did the Cow Cross the Road bfs