Connection Status:
Competition Arena > CyclicWords
SRM 358 · 2007-07-17 · by icanadi · Simple Search, Iteration, String Manipulation
Class Name: CyclicWords
Return Type: int
Method Name: differentCW
Arg Types: (vector<string>)
Problem Statement

Problem Statement

We can think of a cyclic word as a word written in a circle. To represent a cyclic word, we choose an arbitrary starting position and read the characters in clockwise order. So, "picture" and "turepic" are representations for the same cyclic word.

You are given a String[] words, each element of which is a representation of a cyclic word. Return the number of different cyclic words that are represented.

Constraints

  • words will contain between 1 and 50 elements, inclusive.
  • Each element of words will contain between 1 and 50 lowercase letters ('a'-'z'), inclusive.
Examples
0)
{ "picture", "turepic", "icturep", "word", "ordw" }
Returns: 2

"picture", "turepic" and "iceturep" are representations of the same cyclic word. "word" and "ordw" are representations of a second cyclic word.

1)
{ "goran", "igor", "domagoj", "relja" }
Returns: 4
2)
{ "ast", "ats", "tas", "tsa", "sat", "sta", "ttt" }
Returns: 3
3)
{ "aaaa", "aaa", "aa", "a", "as", "sa", "mmm", "kkk" }
Returns: 7
4)
{ "mis", "mi", "je", "polje", "popasel", "ne", "im", "ljepo", "oljep", "sim", "smi" }
Returns: 7

Submissions are judged against all 44 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class CyclicWords with a public method int differentCW(vector<string> words) · 44 test cases · 2 s / 256 MB per case

Submitting as anonymous