Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Minimum period string problem     - How to modify the Emacs Major Mode Shortcuts (Linux)

- Depth understanding of C language (Programming)

- Do not enter password login ssh (Server)

- Smooth upgrade to OpenSSH 6.1 Procedure (Linux)

- Ubuntu 14.04 after the restart the default maximum screen brightness solutions (Linux)

- Perl said method B if A judge (Programming)

- Use apt-p2p up a local Debian package cache (Server)

- MySQL function: group_concat () function (Database)

- CentOS 6.5 install VNC-Server (Linux)

- Linux SSH login without a password (Linux)

- Memcached and Redis (Linux)

- To build a private Docker registry (Server)

- Oracle GoldenGate tutorial Second, configure and use (Database)

- Android in the coordinate system and a method to obtain the coordinates (Programming)

- Let Linux boot methods to enter characters interface and set FrameBuffer resolution methods (Linux)

- Drawing from the Android source code analysis View (Programming)

- Spark read more HBase tables a RDD (Server)

- Linux /var/spool/ insufficient clientmqueue space solutions (Linux)

- MySQL in order by inaccurate results in problems and solutions (Database)

- Kibana use installation (Linux)

  Minimum period string problem
  Add Date : 2018-11-21      
  Problem Description:

If a string may be composed of a string of length n repeatedly obtained, then the string with n cycle. For example, abcabcabcabc 3 cycle (note that it is also 6 and 12 cycles).

Enter a string length does not exceed 100, and outputs its minimum period.

Sample input: ChinaChinaChina

Sample output: 5

problem analysis:
String may have more than one cycle, but just find the smallest one. From small to large can enumerate each period (ie from 1 to the size of the string), once they meet the conditions of output immediately. When the minimum period is not a period that is the length of the output string for itself.

Code is as follows:

#include < stdio.h>
#include < string.h>

int main ()
 char str [101];
 scanf ( "% s", str);
 int i, j, flag = 1; // i recording cycle length, j recording position from the beginning of the second period character
 int len = strlen (str); // len is a string
 for (i = 1; i < = len; i ++)
  if (len% i == 0) // length of the string must be divisible by period
   flag = 1;
   // Check whether the string is cyclical
   for (j = i; j < len; j ++) // str [i] as the first character of the second cycle
    if (str [j]! = str [j% i])
     flag = 0;
   if (flag) // find cycle Bounce
 printf ( "% d \ n", i);
 return 0;
- Boot automatically remove Linux operating history records (Linux)
- Oracle LONG RAW BLOB CLOB type of presentation (Database)
- How common Linux automation tasks (Server)
- Udev: Device Manager for Linux Fundamentals (Linux)
- Python interview must look at 15 questions (Programming)
- Ubuntu / Fedora / CentOS system how to install Plex Media Server 0.9.9 (Linux)
- SUSE Linux install Oracle 10g and problem solving (Linux)
- Apple Mac computer to install Windows 10 Concise Guide (Linux)
- Getting Started with Linux system to learn: How do I know which processes are running on the CPU core (Linux)
- Understanding the Linux load average on other UNIX-Like systems (Linux)
- OpenGL shadow map (Programming)
- JBPM6 Tutorial - Fast Fun JBPM table (Linux)
- Ubuntu 14.04 Fixed update information is outdated error (Linux)
- Ubuntu 14.04 LTS NTFS partition can not access solution (Linux)
- Linux program analysis tool: ldd and nm (Linux)
- How to configure chroot environment in Ubuntu 14.04 (Linux)
- B-tree - ideas and implementation of C language code (Programming)
- The bulk batch multiple rows of data collect (Database)
- Linux kernel TCP / IP parameters analysis and tuning (Linux)
- To setup the Swift language learning environment under linux (Linux)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.