【67.24%】【codeforces 745A】Hongcow Learns the Cyclic Shift
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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
【题解】
模拟一下最后一个字符放到第一个位置的情况;
看看组成的字符串有没有重复就好.
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
//const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
string s;
map <string,int> dic;
int num = 0;
int main()
{
//freopen("F:\\rush.txt","r",stdin);
cin >> s;
int len = s.size();
num = 1;
dic[s] = 1;
rep1(i,1,len)
{
string temp;
temp = s.substr(len-1,1) + s.substr(0,len-1);
if (!dic[temp])
{
dic[temp] = 1;
num++;
}
s = temp;
}
cout << num << endl;
return 0;
}
相关文章
- The method assertEquals(double, double) from the type Assert is deprecated
- k8s报错The connection to the server 192.168.X.X:6443 was refused -did you specify...?docker images镜像丢失
- ORA-22900: the SELECT list item of THE subquery is not a collection type ORACLE 报错 故障修复 远程处理
- ORA-23442: object already exists for the refresh group template ORACLE 报错 故障修复 远程处理
- ORA-23487: object groups “string”.”string” and “string”.”string” do not have the same connection qualifier ORACLE 报错 故障修复 远程处理
- ORA-40120: invalid weight value in the weights table ORACLE 报错 故障修复 远程处理
- ORA-41687: attribute “string” not allowed in the “groupby” specification ORACLE 报错 故障修复 远程处理
- ORA-48140: the specified ADR Base directory does not exist [string] ORACLE 报错 故障修复 远程处理
- ORA-48405: The option in the command is invalid ORACLE 报错 故障修复 远程处理
- ORA-48411: The trace files exceeds the maximum number [string] ORACLE 报错 故障修复 远程处理
- ORA-48442: The control parameter number exceeds the maximum number [string] ORACLE 报错 故障修复 远程处理
- ORA-48463: The value buffer reached the maximum length [string] ORACLE 报错 故障修复 远程处理
- ORA-48489: The input exceeds the maximum length [string] ORACLE 报错 故障修复 远程处理
- ORA-55567: The _highthreshold_undoretention value should be at least string based on the current undo retention settings. ORACLE 报错 故障修复 远程处理
- ORA-64107: The XMLIndex has been successfully altered but the metadata could not be updated. ORACLE 报错 故障修复 远程处理
- ORA-16516: current state is invalid for the attempted operation ORACLE 报错 故障修复 远程处理
- ORA-16742: the standby database “string” has exhausted its quota ORACLE 报错 故障修复 远程处理
- ORA-16812: log apply service not running on apply instance recorded by the broker ORACLE 报错 故障修复 远程处理
- ORA-19164: XQST0085 – It is a static error if the namespace URI in a namespace declaration attribute is a zero-length string, and the implementation does not support [XML Names 1.1]. ORACLE 报错 故障修复 远程处理
- Exploring the Linux Boot Process(linux启动过程描述)
- Oracle 1003:Unlock the Power of Database Management(oracle1003)
- MySQL:Remembering the 1918 Release(mysql1918)
- Oracle Tmp:Unlock the Power of Data Management(oracletmp)
- 修复 Ubuntu 中 “E: The package cache file is corrupted, it has the wrong hash”
- Exploring the Depths of Linux: The Power of the l Command(linux-l)
- Exploring the Versatility of Linux for Efficient PNG Image Processing(linuxpng)
- Exploring the Power of MongoDB: The Definitive Guide to Upgrading Arrays(mongodb更新数组)
- Reviving the Classic: CS 1.6 Now Available on Linux for Gamers Everywhere(cs1.6linux)
- Discovering the Power of Linux: Understanding the pwdx Command!(linuxpwdx)
- Exploring the Benefits of BC Linux for Your Computing Needs!(bclinux)
- 尝试攻克決勝難關The A to Z of Redis(the a什么redis)