網頁

2014年2月14日 星期五

UVA 10298 - Power Strings

 #include <iostream>
 #include <cstdio>
 #include <cmath>
 #include <vector>
 #include <string>
 #include <sstream>
 #include <algorithm>
 #include <map>
 #include <bitset>
 #define MAX 1000000
 using namespace std;
 typedef long long int lli;
 
 int main(int argc, char *argv[]){
   string s;
   bool isPowerString=true;
   while (getline(cin, s) && s!="."){
     for (int i=1; i<=s.length(); ++i){
       if (s.length()%i != 0) continue;
 
       isPowerString = true;
       for (int j=i; j<s.length(); j+=i){
         for (int k=0; k<i; ++k)
           if (s[k] != s[k+j]){
             isPowerString=false;
             break;
           }
         if (isPowerString==false) break;
       }
 
       if (isPowerString==true){
         cout << s.length()/i << endl;
         break;
      }
    }
      
  }
  return 0;
}

沒有留言:

張貼留言