"Bzoj 1031" [JSOI2007] character encryption cipher

Source: Internet
Author: User

1031: [JSOI2007] character encryption cipher time limit: ten Sec Memory Limit: 162 MB
Submit: 3496 Solved: 1384
[Submit] [Status] Description

Like to delve into the problem of JS classmate, and recently fascinated by the encryption method of thinking. One day, he suddenly came up with what he thought was the ultimate encryption: to make a circle of information that needs to be encrypted, it is clear that they have many different ways of reading. For example, it can be read as:

JSOI07 soi07j oi07js i07jso 07JSOI 7jsoi0 sort them by the size of the string: 07JSOI 7jsoi0 i07jso JSOI07 oi07js soi07j read the last column of characters: I0O7SJ, the word after the encryption String (in fact, this encryption method is very easy to crack, because it is suddenly thought out, then ^ ^). However, if the string you want to encrypt is too long, can you write a program to accomplish this task?

Input

The input file contains a row of strings to encrypt. Note that the contents of a string are not necessarily letters, numbers, or symbols.

Output

The output line is the encrypted string.

Sample InputJSOI07Sample OutputI0O7SJHINT

The length of the data string for 100% does not exceed 100000.




Roar ~ First time RANK1!!!


This problem I use recursion, first for each to sort.


It then recursively handles the same section of the current bit, sorting the next one.


Then the output is lined up with the previous one on the ordinal group.


Time complexity is not analyzed.


A dropped after Baidu a bit other people's practice. Unexpectedly is the suffix array, copies the string once, asks the height array to be OK, also is quite naked.


#include <iostream> #include <cstdio> #include <algorithm> #include <cstdlib> #include < String> #include <cstring>using namespace std;int l;char s[100005];struct data{int V,p,now;} C[100005];bool CMP (data a,data b) {return A.V<B.V;} void Solve (int l,int r) {if (l==r) return;int from=l,to=0;for (int i=l+1;i<=r+1;i++) {if (i!=r+1&&c[i].v==c[ FROM].V) To=i;else{if (to) {for (int j=from;j<=to;j++) c[j].now++,c[j].v=s[(C[j].p+c[j].now)%l];sort (c+from,c+to+ 1,CMP); Solve (from,to);} from=i,to=0;}} return;} int main () {        scanf ("%s", s); L=strlen (s); bool F=true;for (int i=0;i<l;i++) {if (i&&s[i]!=s[i-1]) f=false;c[i].now=0,c[i].v= (int) s[i],c [I].p=i;} if (f) {printf ("%s", s); return 0;} Sort (c,c+l,cmp); Solve (0,L-1), for (int i=0;i<l;i++) {if (c[i].p==0) printf ("%c", S[l-1]), Else printf ("%c", S[c[i].p-1]);} Cout<<endl;return 0;}


"Bzoj 1031" [JSOI2007] character encryption cipher

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.