Skip to content

Commit

Permalink
TJU 1679 - Hidden Password
Browse files Browse the repository at this point in the history
  • Loading branch information
marioyc committed Sep 25, 2010
1 parent ffc69b6 commit b4e99f2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
File renamed without changes.
34 changes: 34 additions & 0 deletions Tianjin Online Judge/1679 - Hidden Password.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main(){
int T,L;
char s[100001];

scanf("%d",&T);

while(T--){
scanf("%d %s",&L,s);

int ans = 0,p = 1,l = 0;

while(p<L && ans+l+1<L){
if(s[ans+l]==s[(p+l)%L]) ++l;
else if(s[ans+l]<s[(p+l)%L]){
p = p+l+1;
l = 0;
}else{
ans = max(ans+l+1,p);
p = ans+1;
l = 0;
}
}

printf("%d\n",ans);
}

return 0;
}

0 comments on commit b4e99f2

Please sign in to comment.