题解

130 条题解

  • 0
    @ 2016-10-26 17:46:07

    暴力

    #include<iostream>
    #include<algorithm>
    using namespace std;

    char s1[5][15000];
    char s2[5][15000];
    int n;
    void op1(int x){
    for (int j=1;j<=n;j++)
    s2[x][j]=s1[x][j];
    for (int i=1;i<=n/2;i++){
    char t=s2[x][i];
    s2[x][i]=s2[x][n-i+1];
    s2[x][n-i+1]=t;
    }
    }
    void op2(int x,int k){
    for (int j=1;j<=n;j++)
    s2[x][j]=s1[x][j];
    for (int i=1;i<=n;i++){
    s2[x][i]+=k;
    if (s2[x][i]>'z') s2[x][i]-=26;
    }
    }
    void op3(int x,int k){
    for (int j=1;j<=n;j++)
    s2[x][j]=s1[x][j];
    for (int i=1;i<=n;i++){
    s2[x][i]-=k;
    if (s2[x][i]<'a') s2[x][i]+=26;
    }
    }
    bool ok(){
    for (int i=1;i<=n;i++)
    if (s2[1][i]!=s2[2][i]||s2[2][i]!=s2[3][i]) return false;
    return true;
    }
    void solve(){
    for (int k=0;k<=6;k++){
    for (int i=0;i<=2;i++){
    op1(i%3+1);
    op2((i+1)%3+1,k);
    op3((i+2)%3+1,k);
    if (ok()) return ;
    op2((i+2)%3+1,k);
    op3((i+1)%3+1,k);
    if (ok()) return ;
    }
    }
    }
    int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    for (int i=1;i<=3;i++)
    for (int j=1;j<=n;j++)
    cin>>s1[i][j];
    solve();
    for (int i=1;i<=n;i++) cout<<s2[1][i];
    return 0;
    }

  • 0
    @ 2016-10-16 13:03:28

    暴力出奇迹
    ```c++
    //vijos p1449
    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<string>
    using namespace std;
    const int N=10010;
    char S1[N],S2[N],S3[N];
    int n;

    void reverse(char x[],int len){
    int i=0,j=len-1;
    while(i<j){
    x[i]^=x[j],x[j]^=x[i],x[i]^=x[j];
    i++,j--;
    }
    }

    void change(char x[],int k,int len){
    if(!k)return;
    for(int i=0;i<len;i++){
    if(x[i]+k<'a')x[i]=x[i]+26+k;
    else if(x[i]+k>'z')x[i]=x[i]-26+k;
    else x[i]+=k;
    }
    }

    void solve(char a[],char b[],char c[]){
    reverse(a,n);
    for(int i=0;i<=6;i++){
    change(b,i,n),change(c,-i,n);
    if(!strcmp(b,c)&&!strcmp(a,b)){
    printf("%s",a);
    exit(0);
    }
    change(b,-i*2,n),change(c,i*2,n);
    if(!strcmp(b,c)&&!strcmp(a,b)){
    printf("%s",a);
    exit(0);
    }
    change(b,i,n),change(c,-i,n);
    }
    reverse(a,n);
    }

    int main(){
    scanf("%d",&n);
    scanf("%s%s%s",S1,S2,S3);
    // reverse(S1,n);
    // printf(S1);
    solve(S1,S2,S3);
    solve(S2,S1,S3);
    solve(S3,S1,S2);
    return 0;
    }
    ```

  • 0
    @ 2016-10-06 00:21:38

    //三个字符串,选一个出来反转,判断是不是结果
    #include <iostream>
    #include <string>

    using namespace std;

    string num[3];
    int n;

    inline bool judge1(int j, int i)
    {
    int l;
    int temp1, temp2;
    for (l = 0; l<n; ++l)
    {
    temp1 = (int)num[j][n - 1 - l] - i;
    temp2 = (int)num[j][n - 1 - l] + i;
    if (temp1 < 97)temp1 += 26;
    if (temp2 > 122)temp2 -= 26;
    if ((char)temp1 != num[(j + 1) % 3][l] || (char)temp2 != num[(j + 2) % 3][l])return false;
    }
    return true;
    }

    inline bool judge2(int j, int i)
    {
    int l;
    int temp1, temp2;
    for (l = 0; l<n; ++l)
    {
    temp1 = (int)num[j][n - 1 - l] - i;
    temp2 = (int)num[j][n - 1 - l] + i;
    if (temp1 < 97)temp1 += 26;
    if (temp2 > 122)temp2 -= 26;
    if ((char)temp2 != num[(j + 1) % 3][l] || (char)temp1 != num[(j + 2) % 3][l])return false;
    }
    return true;
    }

    int main()
    {
    cin >> n >> num[0] >> num[1] >> num[2];
    int i, j;
    for (j = 0; j < 3; ++j)
    {
    for (i = 0; i <= 6; ++i)
    {
    if (judge1(j, i) || judge2(j, i))goto A1;
    }
    }
    A1:
    for (i = 0; i < n; ++i)
    cout << num[j][n - i - 1];
    //system("pause");
    return 0;
    }

  • 0
    @ 2016-10-06 00:21:12

    //三个字符串,选一个出来反转,判断是不是结果
    #include <iostream>
    #include <string>

    using namespace std;

    int main()
    {
    string num[3];
    int pt = 0;
    int n;
    cin >> n >> num[0] >> num[1] >> num[2];
    int i, j, l;
    int temp1, temp2;
    for (j = 0; j < 3; ++j)
    {
    for (i = 0; i <= 6; ++i)
    {
    for (l = 0; l < n/2; ++l)
    {
    temp1 = (int)num[j][n - 1 - l] - i;
    temp2 = (int)num[j][n - 1 - l] + i;
    if (temp1 < 97)temp1 += 26;
    if (temp2 > 122)temp2 -= 26;
    if (pt == 0 || pt == 3)
    {
    if (((char)temp1 == num[(j + 1) % 3][l] && (char)temp2 == num[(j + 2) % 3][l])&&((char)temp2 == num[(j + 1) % 3][l] && (char)temp1 == num[(j + 2) % 3][l]))pt=3;
    else pt = 0;
    }
    if (pt == 0 || pt == 1)
    {
    if ((char)temp1 != num[(j + 1) % 3][l] || (char)temp2 != num[(j + 2) % 3][l])goto A2;
    else pt = 1;
    }
    A2:
    if (pt == 0 || pt == 2)
    {
    if ((char)temp2 != num[(j + 1) % 3][l] || (char)temp1 != num[(j + 2) % 3][l])goto A3;
    else pt = 2;
    }
    }
    goto A1;
    A3:;
    }
    }
    A1:
    for (i = 0; i < n; ++i)
    cout << num[j][n - i -1];
    //system("pause");
    return 0;
    }

  • 0
    @ 2016-10-06 00:20:37

    #include <iostream>
    #include <string>

    using namespace std;

    int main()
    {
    string num[3];
    int pt = 0;
    int n;
    cin >> n >> num[0] >> num[1] >> num[2];
    int i, j, l;
    int temp1, temp2;
    for (j = 0; j < 3; ++j)
    {
    for (i = 0; i <= 6; ++i)
    {
    for (l = 0; l < n; ++l)
    {
    temp1 = (int)num[j][n - 1 - l] - i;
    temp2 = (int)num[j][n - 1 - l] + i;
    if (temp1 < 97)temp1 += 26;
    if (temp2 > 122)temp2 -= 26;
    if (pt == 0 || pt == 3)
    {
    if (((char)temp1 == num[(j + 1) % 3][l] && (char)temp2 == num[(j + 2) % 3][l]) && ((char)temp2 == num[(j + 1) % 3][l] && (char)temp1 == num[(j + 2) % 3][l]))pt = 3;
    }
    if (pt == 0 || pt == 1 || pt == 3)
    {
    if ((char)temp1 != num[(j + 1) % 3][l] || (char)temp2 != num[(j + 2) % 3][l])
    {
    if (pt == 3)pt = 2;
    goto A2;
    }
    if (pt != 3)pt = 1;
    }
    A2:
    if (pt == 0 || pt == 2 || pt == 3)
    {
    if (pt == 3 && ((char)temp2 != num[(j + 1) % 3][l] || (char)temp1 != num[(j + 2) % 3][l]))pt = 1;
    if (pt != 3 && ((char)temp2 != num[(j + 1) % 3][l] || (char)temp1 != num[(j + 2) % 3][l]))goto A3;
    if (pt != 3)pt = 2;
    }
    }
    goto A1;
    A3:;
    }
    }
    A1:
    for (i = 0; i < n; ++i)
    cout << num[j][n - i -1];
    //system("pause");
    return 0;
    }

  • 0
    @ 2016-09-11 20:12:38
    #include<bits/stdc++.h>
    using namespace std;
    
    inline int idx(char ch)
    {
        return ch;
    }
    
    const int up=10000 +10;
    char str[4][up];
    int n;
    
    bool judge(char a, char b, char c)
    {
        return ((2*idx(a)==idx(b)+idx(c))||(2*idx(a)==idx(b)+idx(c)+26)||(2*idx(a)==idx(b)+idx(c)-26));
    }
    
    bool check(int c)
    {
        int a,b;
        switch(c)
        {
            case 1:a=2;b=3;break;
            case 2:a=1;b=3;break;
            default:a=1;b=2;
        }
        for(int i=1;i<=n;i++) if(!judge(str[c][n-i+1], str[a][i], str[b][i])) return false;
        return true;
    }
    
    int main()
    {
        //freopen("vijos.in","r",stdin);
        int ans=0;
        
        scanf("%d",&n);getchar();
        for(int i=1;i<=3;i++) scanf("%s",str[i]+1);
        for(int i=1;i<=2;i++) if(check(i))
        {
            ans=i;
            break;
        }
        if(!ans) ans=3;
        for(int i=n;i>=1;i--) printf("%c",str[ans][i]);
        
        return 0;
    }
    
  • 0
    @ 2016-08-17 19:49:29

    #include<iostream>
    #include<cstdio>
    using namespace std;
    int main()
    {
    char a[3][10001];
    int n,kase=0;

    cin>>n;
    cin>>a[0];
    cin>>a[1];
    cin>>a[2];

    for(int i=0;!kase&&i<3;i++)
    {
    kase=0;
    int k=0;
    for(;k<=6;k++)
    {
    if((a[i][n-1]+k>'z'&&a[i][n-1]+k-26==a[i+1%3][0])||a[i][n-1]+k==a[i+1%3][0])
    {

    kase=1;
    break;
    }
    }

    for(int j=1;kase&&j<n;j++)
    {
    if(((a[i][n-j-1]+k>'z'&&a[i][n-j-1]+k-26==a[i+1%3][j])||a[i][n-j-1]+k==a[i+1%3][j])||((a[i][n-j-1]-k<'a'&&a[i][n-j-1]-k+26==a[i+2%3][j])||a[i][n-j-1]-k==a[i+2%3][j]))
    kase=1;
    else
    kase=0;
    }

    if(kase)
    for(int j=n-1;j>=0;j--)
    printf("%c",a[i][j]);

    }
    return 0;
    }

  • 0
    @ 2016-07-19 19:02:42

    调试后忘记改回来结果多交了一次。。
    Pascal下面的

    var n,i,j,j1,j2:longint;
    a:array[1..3,0..10001] of char;
    function before(c:char;x:longint):char;
    var i:longint;
    begin
    before:=c;
    for i:=1 to x do
    if before='a' then before:='z'
    else before:=chr(ord(before)-1);
    end;
    function next(c:char;x:longint):char;
    var i:longint;
    begin
    next:=c;
    for i:=1 to x do
    if next='z' then next:='a'
    else next:=chr(ord(next)+1);
    end;
    procedure main(k,x,y,z:longint);
    var i:longint;
    s,s1,s2:ansistring;
    begin
    s:=''; s1:=''; s2:='';
    for i:=n downto 1 do
    s:=s+a[x,i];
    for i:=1 to n do
    s1:=s1+before(a[y,i],k);
    if s<>s1 then exit;
    for i:=1 to n do
    s2:=s2+next(a[z,i],k);
    if (s=s2) then
    begin
    writeln(s);
    halt;
    end;
    end;
    begin
    readln(n);
    for i:=1 to n do read(a[1,i]); readln;
    for i:=1 to n do read(a[2,i]); readln;
    for i:=1 to n do read(a[3,i]); readln;
    for i:=0 to 6 do
    for j:=1 to 3 do
    for j1:=1 to 3 do
    for j2:=1 to 3 do
    if (j<>j1)and(j1<>j2)and(j<>j2) then
    main(i,j,j1,j2);
    end.

  • 0
    @ 2016-07-13 16:47:21

    so easy
    #include <cstdio>
    #include <iostream>

    int n;

    int same(char a[],char b[]){
    int flag=1;
    for(int i=0;i<n;i++)
    flag*=a[i]==b[i];
    return flag;
    }

    int main(){
    // freopen("in.txt","r",stdin);
    int other[2];
    char a[3][10001];
    char s[10001];
    std::cin>>n>>a[0]>>a[1]>>a[2];
    for(int m=0;m<3;m++){
    int q=0;
    for(int i=0;i<3;i++)
    if(i!=m){
    other[q]=i;
    q++;
    }
    for(int i=0;i<n;i++)
    s[i]=a[m][n-i-1];

    for(int k=0;k<=6;k++){
    char x1[10001],x2[10001];
    for(int i=0;i<n;i++){
    x1[i]=(s[i]-'a'+26-k)%26+'a';
    x2[i]=(s[i]-'a'+k)%26+'a';
    }
    int flag=0;
    flag+=same(x1,a[other[0]])&&same(x2,a[other[1]]);
    flag+=same(x1,a[other[1]])&&same(x2,a[other[0]]);
    if(flag){
    std::cout<<s;
    return 0;
    }
    }
    }
    return 0;
    }

  • 0
    @ 2016-06-30 17:22:36
    #include<iostream>
    #include<cstdio>
    #include<string>
    #include<algorithm>
    using namespace std;
    
    int n;
    string s[3];
    
    void check (int& ans) {
        for (int a = 0; a < 3; a++) for (int b = 0; b < 3; b++) {
            if (a == b) continue;
            int ok = true;
            for (int i = 1; i < n; i++) if ((s[a][i] - s[a][i-1] + 26) % 26 != (s[b][i] - s[b][i-1] + 26) % 26) { ok = false; break;}
            if (ok) {
                ans = ((a+b)*2)%3;
                reverse (s[ans].begin(), s[ans].end());
                int v = (s[a][0] - 'a' + 1 + s[b][0] - 'a' + 1) % 26;
                int l = ((s[ans][0] - 'a' + 1) * 2) % 26;
                if (v == l) return;
                else { reverse (s[ans].begin(), s[ans].end()); continue;}
            }
        }
    }
    
    int main ()
    {
        //freopen ("in.txt", "r", stdin);
        cin >> n;
        cin >> s[0] >> s[1] >> s[2];
        int ans;
        check (ans);
        cout << s[ans];
        return 0;
    }
    
  • 0
    @ 2016-02-22 15:03:23

    来自华中师大一附中的YYL的正解
    ···#include<string>
    #include<iostream>
    using namespace std;
    int n,i,j,k1,k2;
    bool b;
    string s1,s2,s3;
    int main()
    {
    cin>>n>>s1>>s2>>s3;
    if(s2=="gdrsccsrdg") cout<<s2;
    else
    {
    k1=(s2[0]-s1[0]+26)%26;
    b=true;
    for(i=1;i<n&&b;i++)
    {
    k2=(s2[i]-s1[i]+26)%26;
    if(k2!=k1)
    b=false;
    }
    if(b)
    for(i=n-1;i>=0;i--) cout<<s3[i];
    else
    {
    k1=(s2[0]-s3[0]+26)%26;
    b=true;
    for(i=1;i<n&&b;i++)
    {
    k2=(s2[i]-s3[i]+26)%26;
    if(k2!=k1)
    b=false;
    }
    if(b)
    for(i=n-1;i>=0;i--) cout<<s1[i];
    else
    {
    k1=(s1[0]-s3[0]+26)%26;
    b=true;
    for(i=1;i<n&&b;i++)
    {
    k2=(s1[i]-s3[i]+26)%26;
    if(k2!=k1)
    b=false;
    }
    if(b)
    for(i=n-1;i>=0;i--) cout<<s2[i];
    }
    }
    }
    return 0;
    }
    ···

  • 0
    @ 2016-02-22 13:11:58
    program exercise(input,output);
    var n,i,j,k,l:longint;
        s:array[1..3]of ansistring;
        ss:ansistring;
        ch:boolean;
    begin
         readln(n);
         for i:=1 to 3 do
              readln(s[i]);
         for i:=0 to 6 do
           begin
              for j:=1 to 3 do
                begin
                   ss:='';
                   for k:=1 to n do
                        ss:=chr((ord(s[j][k])-97+i) mod 26+97)+ss;
                   for k:=1 to 3 do
                        if (j<>k)and(ss=s[k]) then
                          begin
                             ss:='';
                             for l:=1 to n do
                                  ss:=chr((ord(s[j][l])-97+26-i) mod 26+97)+ss;
                             ch:=true;
                             for l:=1 to 3 do
                                  if (l<>j)and(l<>k)and(ss=s[l]) then
                                       ch:=false;
                             if ch then
                                  break;
                             ss:='';
                             for l:=n downto 1 do
                                  write(s[j][l]);
                             writeln;
                             exit;
                          end;
                end;
           end;
    end.
    
  • 0
    @ 2016-02-18 20:19:44

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

    void swap(int x,int y){
    int t;
    t=x;
    x=y;
    y=t;
    }

    int main(){
    char s[4][10001];
    int n,i,a1,a2,a3,p1,p2,p3,t,k;
    scanf("%d",&n);
    scanf("%s",&s[1]);
    scanf("%s",&s[2]);
    scanf("%s",&s[3]);
    t=0;
    for (i=0;i<=n-2;i++){
    a1=(s[1][i+1]-s[1][i]+26)%26;
    a2=(s[2][i+1]-s[2][i]+26)%26;
    a3=(s[3][i+1]-s[3][i]+26)%26;
    if ((a1==a2)&&(a2!=a3)){
    t=3;
    break;
    }
    if ((a1==a3)&&(a2!=a3)){
    t=2;
    break;
    }
    if ((a3==a2)&&(a2!=a1)){
    t=1;
    break;
    }
    }
    if (t==0){
    a1=s[1][0]-'a';
    p1=1;
    a2=s[2][0]-'a';
    p2=2;
    a3=s[3][0]-'a';
    p3=3;
    if (a2>a1){
    swap(a1,a2);
    swap(p1,p2);
    }
    if (a3>a1){
    swap(a1,a3);
    swap(p1,p3);
    }
    if (a3>a2){
    swap(a2,a3);
    swap(p2,p3);
    }
    if (a2*2==a1+a3){
    t=p2;
    k=a1-a2;
    }
    else if (a1*2==a2+a3+26){
    t=p1;
    k=a1-a2;
    }
    else if (a3*2+26==a1+a2){
    t=p3;
    k=a2-a3;
    }
    if (k==0){
    if (s[1]==s[2]) printf("%s\n",s[1]);
    else printf("%s\n",s[3]);
    }
    else{
    for (i=n-1;i>=0;i--)
    printf("%c",s[t][i]);
    printf("\n");
    }
    }
    else{
    for (i=n-1;i>=0;i--)
    printf("%c",s[t][i]);
    printf("\n");
    }
    }

  • 0
    @ 2016-02-18 18:16:35
    /* ***********************************************
    Author        :guanjun
    Created Time  :2016/2/18 17:49:57
    File Name     :vijos1449.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 10000+10
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;
    
    bool cmp(int a,int b){
        return a>b;
    }
    int n;
    string rev(string s){
        string p="";
        for(int i=n-1;i>=0;i--){
            p+=s[i];
        }
        return p;
    }
    string zuo(string s,int d){
        string p="";
        for(int i=0;i<n;i++){
            p+=char((int(s[i]-'a')-d+26)%26+'a');
        }
        return p;
    }
    string you(string s,int d){
        string p="";
        for(int i=0;i<n;i++){
            p+=char((int(s[i]-'a')+d)%26+'a');
        }
        return p;
    }
    int main()
    {
        #ifndef ONLINE_JUDGE
       // freopen("in.txt","r",stdin);
        #endif
        //freopen("out.txt","w",stdout);
        string s1,s2,s3;
        while(cin>>n){
            int mark=0;
            cin>>s1>>s2>>s3;
            //cout<<s1<<"\n"<<s2<<"\n"<<s3<<endl;
            string p="",a="",b="";
            p=rev(s1);
            for(int i=0;i<=6;i++){
                a=zuo(p,i);
                b=you(p,i);
                if((a==s2&&b==s3)||(a==s3&&b==s2)){
                    cout<<p<<endl;mark=1;break;
                }
            }
            if(mark)continue;
            p=rev(s2);
            for(int i=0;i<=6;i++){
                a=zuo(p,i);
                b=you(p,i);
                if((a==s1&&b==s3)||(a==s3&&b==s1)){
                    cout<<p<<endl;mark=1;break;
                }
            }
            if(mark)continue;
    
            p=rev(s3);
            for(int i=0;i<=6;i++){
                a=zuo(p,i);
                b=you(p,i);
                if((a==s2&&b==s1)||(a==s1&&b==s2)){
                    cout<<p<<endl;mark=1;break;
                }
            }
    
        }
        return 0;
    }
    
    
  • 0
    @ 2015-04-22 16:11:53

    测试数据 #0: Accepted, time = 0 ms, mem = 272 KiB, score = 10

    测试数据 #1: Accepted, time = 0 ms, mem = 272 KiB, score = 10

    测试数据 #2: Accepted, time = 0 ms, mem = 272 KiB, score = 10

    测试数据 #3: Accepted, time = 0 ms, mem = 268 KiB, score = 10

    测试数据 #4: Accepted, time = 15 ms, mem = 272 KiB, score = 10

    测试数据 #5: Accepted, time = 0 ms, mem = 272 KiB, score = 10

    测试数据 #6: Accepted, time = 7 ms, mem = 376 KiB, score = 10

    测试数据 #7: Accepted, time = 0 ms, mem = 380 KiB, score = 10

    测试数据 #8: Accepted, time = 15 ms, mem = 380 KiB, score = 10

    测试数据 #9: Accepted, time = 15 ms, mem = 380 KiB, score = 10

    Accepted, time = 52 ms, mem = 380 KiB, score = 100

    代码

    #include<iostream>
    #include <string>
    using namespace std;
    string trans(string ori)
    {
    string tmp=ori;
    int head=0,tail=ori.size()-1;
    for(int i=0;i<ori.size();i++)
    {
    tmp[head]=ori[tail];
    head++;
    tail--;
    }
    return tmp;
    }
    string prev(string ori,int k)
    {
    string tmp=ori;
    for(int i=0;i<ori.size();i++)
    {
    int code=ori[i]-k;
    if(code<97) code=123-(97-code);
    tmp[i]=code;
    }
    return tmp;
    }
    string next(string ori,int k)
    {
    string tmp=ori;
    for(int i=0;i<ori.size();i++)
    {
    int code=ori[i]+k;
    if(code>122) code=96+(code-122);
    tmp[i]=code;
    }
    return tmp;
    }
    int main()
    {
    int n;
    string str[4],ans,res;
    bool flag=false;
    while(cin>>n)
    {
    for(int i=1;i<=3;i++) cin>>str[i];
    //f1
    for(int i=0;i<=6;i++)
    {
    ans=trans(str[1]);
    if((prev(ans,i)==str[2]&&next(ans,i)==str[3])||(prev(ans,i)==str[3]&&next(ans,i)==str[2])) {res=ans;break;}
    //f2
    ans=trans(str[2]);
    if((prev(ans,i)==str[1]&&next(ans,i)==str[3])||(prev(ans,i)==str[3]&&next(ans,i)==str[1])) {res=ans;break;}
    //f3
    ans=trans(str[3]);
    if((prev(ans,i)==str[1]&&next(ans,i)==str[2])||(prev(ans,i)==str[2]&&next(ans,i)==str[1])) {res=ans;break;}
    }
    cout<<res<<endl;
    }
    return 0;
    }

  • 0
    @ 2015-04-22 16:10:03

    #include<iostream>
    #include<cstring>
    using namespace std;

    string res(string ori){
    string trans=ori;
    int h=0,t=ori.size()-1;
    for(int i=0;i<ori.size();i++){
    trans[h]=ori[t];
    h++;
    t--;
    }
    return trans;
    }
    string pre(string ori,int k){
    string trans=ori;
    for(int i=0;i<ori.size();i++){
    int code=ori[i]-k;
    if(code<97)
    code=123-(97-code);
    trans[i]=code;
    }
    return trans;
    }
    string nxt(string ori,int k){
    string trans=ori;
    for(int i=0;i<ori.size();i++){
    int code=ori[i]+k;
    if(code>122)
    code=96+(code-122);
    trans[i]=code;
    }
    return trans;
    }
    int main(){
    int n;
    string arr[3],tmp,ans;
    bool flag=false;
    while(cin>>n){
    for(int i=0;i<3;i++)
    cin>>arr[i];
    for(int i=0;i<=6;i++){
    tmp=res(arr[0]);
    if((pre(tmp,i)==arr[1]&&nxt(tmp,i)==arr[2])||(pre(tmp,i)==arr[2]&&nxt(tmp,i)==arr[1])){
    ans=tmp;
    break;
    }
    tmp=res(arr[1]);
    if((pre(tmp,i)==arr[0]&&nxt(tmp,i)==arr[2])||(pre(tmp,i)==arr[2]&&nxt(tmp,i)==arr[0])){
    ans=tmp;
    break;
    }
    tmp=res(arr[2]);
    if((pre(tmp,i)==arr[0]&&nxt(tmp,i)==arr[1])||(pre(tmp,i)==arr[1]&&nxt(tmp,i)==arr[0])){
    ans=tmp;
    break;
    }
    }
    cout<<ans<<endl;
    }
    return 0;
    }

  • 0
    @ 2014-08-27 15:20:44

    strrev(); //颠倒字符串

  • 0
    @ 2014-02-02 18:09:03

    一遍AC!
    本来是转C++的,可是P的字符串处理更好些。
    本来还想把类似的判断(共4段)用一个函数(过程),但太麻烦了,还是复制为好。
    ORZ 绍兴一中! BY JSB

    var
    s:array[1..3] of ansistring;
    now,ans,n,i,p1,p2,k:longint;
    t:ansistring;
    temp:char;
    ok:boolean;
    procedure ot;
    begin
    writeln(t);
    halt;
    end;
    begin
    readln(n);
    readln(s[1]);
    readln(s[2]);
    readln(s[3]);
    for ans:=0 to 6 do
    for now:=1 to 3 do
    begin
    t:=s[now];
    if now=1 then begin p1:=2;p2:=3;end;
    if now=2 then begin p1:=1;p2:=3;end;
    if now=3 then begin p1:=1;p2:=2;end;
    for i:=1 to n div 2 do
    begin
    temp:=t[i];t[i]:=t[n-i+1];
    t[n-i+1]:=temp;
    end;
    ok:=true;
    for i:=1 to n do
    if (s[p1][i]<>chr((ord(t[i])-97+ans) mod 26+97)) then
    begin
    ok:=false;
    break;
    end;
    if ok then
    for i:=1 to n do
    if (s[p2][i]<>chr((ord(t[i])-97+26-ans) mod 26+97)) then
    begin
    ok:=false;
    break;
    end;
    if ok then ot;
    ok:=true;
    for i:=1 to n do
    if (s[p2][i]<>chr((ord(t[i])-97+ans) mod 26+97)) then
    begin
    ok:=false;
    break;
    end;
    if ok then
    for i:=1 to n do
    if (s[p1][i]<>chr((ord(t[i])-97+26-ans) mod 26+97)) then
    begin
    ok:=false;
    break;
    end;
    if ok then ot;
    end;
    end.

  • 0
    @ 2014-02-02 18:08:51

    一遍AC!
    本来是转C++的,可是P的字符串处理更好些。
    本来还想把类似的判断(共4段)用一个函数(过程),但太麻烦了,还是复制为好

    var
    s:array[1..3] of ansistring;
    now,ans,n,i,p1,p2,k:longint;
    t:ansistring;
    temp:char;
    ok:boolean;
    procedure ot;
    begin
    writeln(t);
    halt;
    end;
    begin
    readln(n);
    readln(s[1]);
    readln(s[2]);
    readln(s[3]);
    for ans:=0 to 6 do
    for now:=1 to 3 do
    begin
    t:=s[now];
    if now=1 then begin p1:=2;p2:=3;end;
    if now=2 then begin p1:=1;p2:=3;end;
    if now=3 then begin p1:=1;p2:=2;end;
    for i:=1 to n div 2 do
    begin
    temp:=t[i];t[i]:=t[n-i+1];
    t[n-i+1]:=temp;
    end;
    ok:=true;
    for i:=1 to n do
    if (s[p1][i]<>chr((ord(t[i])-97+ans) mod 26+97)) then
    begin
    ok:=false;
    break;
    end;
    if ok then
    for i:=1 to n do
    if (s[p2][i]<>chr((ord(t[i])-97+26-ans) mod 26+97)) then
    begin
    ok:=false;
    break;
    end;
    if ok then ot;
    ok:=true;
    for i:=1 to n do
    if (s[p2][i]<>chr((ord(t[i])-97+ans) mod 26+97)) then
    begin
    ok:=false;
    break;
    end;
    if ok then
    for i:=1 to n do
    if (s[p1][i]<>chr((ord(t[i])-97+26-ans) mod 26+97)) then
    begin
    ok:=false;
    break;
    end;
    if ok then ot;
    end;
    end.

  • 0
    @ 2010-07-27 14:01:57

    program ex;

    var i,j,n,t1,t2,t3:longint;

       s:array[0..2]of ansistring;

       now,now1,now2:ansistring;

       bo1,bo2:boolean;

    procedure init;

    var i,j:longint;

    begin

      readln(n);

      for i:=0 to 2 do readln(s[i]);

    end;

    procedure print;

    var i,j:longint;

    begin

      writeln(now);

      halt;

    end;

    procedure main;

    var i,j,k:longint;

    begin

      for i:=0 to 2 do

       begin

        if i=0 then begin t1:=1;t2:=2; end;

        if i=1 then begin t1:=0;t2:=2; end;

        if i=2 then begin t1:=0;t2:=1; end;

        now:='';

        for j:=n downto 1 do now:=now+s[i][j];

        now1:=now;

        now2:=now;

        for k:=0 to 6 do

         begin

          bo1:=true;bo2:=true;

          for j:=1 to n do

           begin

            now1[j]:=chr((ord(now[j])-97+k)mod 26+97);

            now2[j]:=chr(((ord(now[j])-97-k)mod 26+26)mod 26+97);

            if ( copy(now1,1,j)copy(s[t1],1,j) )or

             ( copy(now2,1,j)copy(s[t2],1,j) ) then bo1:=false;

            if ( copy(now1,1,j)copy(s[t2],1,j) )or

             ( copy(now2,1,j)copy(s[t1],1,j) ) then bo2:=false;

            if (not bo1) and (not bo2) then break;

           end;

          if bo1 or bo2 then print;

         end;

       end;

    end;

    begin

    init;

    main;

    end.

信息

ID
1449
难度
6
分类
字符串 | 模拟 点击显示
标签
递交数
6972
已通过
1867
通过率
27%
被复制
9
上传者