題意:
(from luckycat)
解法:
直接暴力檢查任何長度的子字串。
TAG: ad hoc,
注意:
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Tittle: 10298 - Power Strings | |
* Author: Cheng-Shih, Wong | |
* Date: 2015/06/11 | |
*/ | |
// include files | |
#include <bits/stdc++.h> | |
using namespace std; | |
// definitions | |
#define FOR(i,a,b) for( int i=(a),_n=(b); i<=_n; ++i ) | |
#define clr(x,v) memset( x, v, sizeof(x) ) | |
#define N 1000005 | |
// declarations | |
char buf[N]; | |
int sl; | |
int ans; | |
// functions | |
// main function | |
int main( void ) | |
{ | |
bool ok; | |
// input | |
while( scanf( "%s", buf )==1 && buf[0]!='.' ) { | |
sl = strlen( buf ); | |
ans = 1; | |
FOR( i, 1, sl ) if( (sl%i)==0 ) { | |
ok = true; | |
FOR( j, i, sl-1 ) if( buf[j]!=buf[j%i] ) { | |
ok = false; | |
break; | |
} | |
if( ok ) { | |
ans = sl/i; | |
break; | |
} | |
} | |
printf( "%d\n", ans ); | |
} | |
return 0; | |
} |
沒有留言:
張貼留言
任何意見都樂意傾聽