130 条题解
-
0Chris9152 LV 5 @ 2021-10-26 16:59:17
数据有亿点水,只需要判断首字母
#include<iostream> #include<cstdio> using namespace std; int n; string a1,a2,a3; int jud(string a,string b,string c) { int i,j; for(i=0,j=n-1;i<=n-1,j>=0;i++,j--) { int t1=a[i]-'a'+1; int t2=b[i]-'a'+1; int t3=c[j]-'a'+1; int mark=0; for(int k=0;k<=26;k++) { if(t1==(t3+k-1)%26+1 && t2==(t3-k-1+26)%26+1)//玄妙的取模运算,可以省掉四个判断 { mark=1;break;} if(t2==(t3+k-1)%26+1 && t1==(t3-k-1+26)%26+1) { mark=1;break;} } if(mark) { continue; } else return 0; } return 1; } void output(string a)//反向输出找到的倒序字串 { int i; for(i=n-1;i>=0;i--) cout<<a[i]; } int main() { cin>>n; cin>>a1>>a2>>a3; if(jud(a1,a2,a3))//分别判断倒序的字串究竟是哪个 { output(a3); return 0; } if(jud(a2,a3,a1)) { output(a1); return 0; } if(jud(a3,a1,a2)) { output(a2); return 0; } //system("pause"); }
芜湖,废了我1个小时
-
02021-05-20 15:47:50@
``java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;/**
* @author wpx
* @version V1.0
* @Package com.algorithm
* @date 2021/5/20 9:40
*/
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
sc.nextLine();
String strOne = sc.nextLine().trim();
String strTwo = sc.nextLine().trim();
String strThree = sc.nextLine().trim();
// a = 97 z = 122
// 先找出前后移动字母的加密方式
// 先比较 第一个和第二个字符
String realStr = null;
realStr = hasEqualGap(strOne, strTwo);
if(realStr != null && realStr.equals(getTrueValue(strThree))){
System.out.println(realStr);
return;
}
realStr = hasEqualGap(strOne, strThree);
if(realStr != null && realStr.equals(getTrueValue(strTwo))){
System.out.println(realStr);
return;
}realStr = hasEqualGap(strTwo, strThree);
if(realStr != null && realStr.equals(getTrueValue(strOne))){
System.out.println(realStr);
return;
}
}
private static String hasEqualGap(String strOne, String strTwo){
Integer gap = null;
boolean hasEqualGap = true;
StringBuilder builder = new StringBuilder();
for(int i = 0; i < strOne.length(); i++){
final char charOne = strOne.charAt(i);
final char charTwo = strTwo.charAt(i);
int nowGap = Math.abs(charOne - charTwo) ;
if(nowGap > 12){
nowGap = Math.abs(26 - nowGap);
}
if(gap == null) {
gap = nowGap;
} else if(gap != nowGap){
return null;
}
if(gap == nowGap){
// 假设 strOne 为向前移动
if(getTrueChar((char)(charOne - gap/2)) == getTrueChar((char)(charTwo + gap/2)) ) {
builder.append(getTrueChar((char)(charOne - gap/2)));
} else if (getTrueChar((char)(charOne + gap/2)) == getTrueChar((char)(charTwo - gap/2))) {
builder.append(getTrueChar((char)(charOne + gap/2)));
} else {
return null;
}}
}
return builder.toString();
}public static char getTrueChar(char charValue){
if(charValue > 122) {
return (char) (96 + (charValue - 122));
} else if(charValue < 97) {
return (char) (123 + (charValue - 97));
} else {
return charValue;
}
}private static String getTrueValue(String str) {
StringBuilder stringBuilder = new StringBuilder(str);
stringBuilder.reverse();
return stringBuilder.toString();
}
} -
02020-11-05 11:33:55@
#include <stdio.h>
#include <string.h>
#include <math.h>//翻转字符串函数
void versech(char a[],int N){
int i;
char ch;
for(i=0;i<N/2;i++){
ch=a[i];
a[i]=a[N-1-i];
a[N-1-i]=ch;
}
}//字符串相加函数
void add_str(char a[],char b[],char c[],int N){
int i;
for(i=0;i<N;i++){
//若某两个字符之差绝对值在12以内,说明没有分布在‘a’的两侧
if(abs((a[i]-'a')%26-(b[i]-'a')%26)<=12)
c[i]=(((a[i]-'a')%26+(b[i]-'a')%26)/2)%26+'a';
//否则在'a'的两侧需将两字符之和加上26
else
c[i]=(((a[i]-'a')%26+(b[i]-'a')%26+26)/2)%26+'a';
}
//注意,若使用字符串函数,要记得字符串最后加'\0',否则使用字符串函数会出错
c[N]='\0';
}int main()
{
char a1[10001];
char a2[10001];
char a3[10001];
char add[10001];
int n;
scanf("%d",&n);
scanf("%s",a1);
scanf("%s",a2);
scanf("%s",a3);
//翻转a1
versech(a1,n);
add_str(a2,a3,add,n);
if(!strcmp(a1,add))
printf("%s\n",a1);
else{
//否则将a1翻转回来,继续翻转a2
versech(a1,n);
versech(a2,n);
add_str(a1,a3,add,n);
if(!strcmp(a2,add))
printf("%s\n",a2);
else{
//否则将a2翻转回来,继续翻转a3
versech(a2,n);
versech(a3,n);
add_str(a1,a2,add,n);
if(!strcmp(add,a3))
printf("%s\n",a3);
}
}
return 0;}
-
02020-03-29 12:38:27@
#include<iostream>
#include<cstdlib>
#include<string>
#include<array>
#include<vector>
using namespace std;
string decrypt1(string a, int k,int n)
{
int temp;
const array<char, 27>letters = { '0','a','b','c','d','e','f','g','h','i','j','k','l','m','n',
'o','p','q','r','s','t','u','v','w','x' ,'y','z' };
for (int i = 0; i < n; i++)
{
for (int s = 0; s < 27; s++)
{
if (a[i] == letters[s])
{
temp = s;
break;
}
}
if (temp + k <= 26)
a[i] = letters[temp + k];
else
a[i] = letters[temp + k - 26];
}
return a;
}
string decrypt2(string a, int k, int n)
{
int temp;
const array<char, 27>letters = { '0','a','b','c','d','e','f','g','h','i','j','k','l','m','n',
'o','p','q','r','s','t','u','v','w','x' ,'y','z' };
for (int i = 0; i < n; i++)
{
for (int s = 0; s < 27; s++)
{
if (a[i] == letters[s])
{
temp = s;
break;
}
}
if (temp - k > 0)
a[i] = letters[temp - k];
else
a[i] = letters[temp - k + 26];
}
return a;
}
string decrypt3(string a, int n)
{
vector<char>temp(n);
for (int k = 0; k < n; k++)
{
temp[n - k - 1] = a[k];
}
for (int i = 0; i < n; i++)
{
a[i] = temp[i];
}
return a;
}
int main()
{
int n;
string s1, s2, s3, s4;
cin >> n >> s1 >> s2 >> s3;
for (int j = 0; j <= 6; j++)
{
if (decrypt1(s1, j, n) == decrypt2(s2, j, n)&& decrypt1(s1, j, n)==decrypt3(s3,n))
{
s4 = decrypt1(s1, j, n);
cout << s4;
break;
}
if (decrypt1(s2, j, n) == decrypt2(s3, j, n) && decrypt1(s2, j, n) == decrypt3(s1, n))
{
s4 = decrypt1(s2, j, n);
cout << s4;
break;
}
if (decrypt1(s3, j, n) == decrypt2(s1, j, n) && decrypt1(s3, j, n) == decrypt3(s2, n))
{
s4 = decrypt1(s3, j, n);
cout << s4;
break;
}
if (decrypt1(s2, j, n) == decrypt2(s1, j, n) && decrypt1(s2, j, n) == decrypt3(s3, n))
{
s4 = decrypt1(s2, j, n);
cout << s4;
break;
}
if (decrypt1(s3, j, n) == decrypt2(s2, j, n) && decrypt1(s3, j, n) == decrypt3(s1, n))
{
s4 = decrypt1(s3, j, n);
cout << s4;
break;
}
if (decrypt1(s1, j, n) == decrypt2(s3, j, n) && decrypt1(s1, j, n) == decrypt3(s2, n))
{
s4 = decrypt1(s1, j, n);
cout << s4;
break;
}
}
return 0;
} -
02020-03-29 12:37:55@
#include<iostream>
#include<cstdlib>
#include<string>
#include<array>
#include<vector>
using namespace std;
string decrypt1(string a, int k,int n)
{
int temp;
const array<char, 27>letters = { '0','a','b','c','d','e','f','g','h','i','j','k','l','m','n',
'o','p','q','r','s','t','u','v','w','x' ,'y','z' };
for (int i = 0; i < n; i++)
{
for (int s = 0; s < 27; s++)
{
if (a[i] == letters[s])
{
temp = s;
break;
}
}
if (temp + k <= 26)
a[i] = letters[temp + k];
else
a[i] = letters[temp + k - 26];
}
return a;
}
string decrypt2(string a, int k, int n)
{
int temp;
const array<char, 27>letters = { '0','a','b','c','d','e','f','g','h','i','j','k','l','m','n',
'o','p','q','r','s','t','u','v','w','x' ,'y','z' };
for (int i = 0; i < n; i++)
{
for (int s = 0; s < 27; s++)
{
if (a[i] == letters[s])
{
temp = s;
break;
}
}
if (temp - k > 0)
a[i] = letters[temp - k];
else
a[i] = letters[temp - k + 26];
}
return a;
}
string decrypt3(string a, int n)
{
vector<char>temp(n);
for (int k = 0; k < n; k++)
{
temp[n - k - 1] = a[k];
}
for (int i = 0; i < n; i++)
{
a[i] = temp[i];
}
return a;
}
int main()
{
int n;
string s1, s2, s3, s4;
cin >> n >> s1 >> s2 >> s3;
for (int j = 0; j <= 6; j++)
{
if (decrypt1(s1, j, n) == decrypt2(s2, j, n)&& decrypt1(s1, j, n)==decrypt3(s3,n))
{
s4 = decrypt1(s1, j, n);
cout << s4;
break;
}
if (decrypt1(s2, j, n) == decrypt2(s3, j, n) && decrypt1(s2, j, n) == decrypt3(s1, n))
{
s4 = decrypt1(s2, j, n);
cout << s4;
break;
}
if (decrypt1(s3, j, n) == decrypt2(s1, j, n) && decrypt1(s3, j, n) == decrypt3(s2, n))
{
s4 = decrypt1(s3, j, n);
cout << s4;
break;
}
if (decrypt1(s2, j, n) == decrypt2(s1, j, n) && decrypt1(s2, j, n) == decrypt3(s3, n))
{
s4 = decrypt1(s2, j, n);
cout << s4;
break;
}
if (decrypt1(s3, j, n) == decrypt2(s2, j, n) && decrypt1(s3, j, n) == decrypt3(s1, n))
{
s4 = decrypt1(s3, j, n);
cout << s4;
break;
}
if (decrypt1(s1, j, n) == decrypt2(s3, j, n) && decrypt1(s1, j, n) == decrypt3(s2, n))
{
s4 = decrypt1(s1, j, n);
cout << s4;
break;
}
}
return 0;
} -
02019-09-22 21:04:56@
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int n;
string h1(string s)//方法1
{ int i,t;
string f;
for(i=0;i<n/2;i++)
{ f[0]=s[i];
s[i]=s[n-i-1];
s[n-i-1]=f[0];
}
return s;
}
string h2(string s,int k)//方法2 逆向
{ int i,t;
for(i=0;i<n;i++)
for(t=0;t<k;t++)
if(s[i]-1<'a') s[i]='z';
else s[i]=s[i]-1;
return s;
}
string h3(string s,int k)//方法3 逆向
{ int i,t;
for(i=0;i<n;i++)
for(t=0;t<k;t++)
if(s[i]+1>'z') s[i]='a';
else s[i]=s[i]+1;
return s;
}
int main()
{ int i;
string s1,s2,s3;
cin>>n;
cin>>s1>>s2>>s3;
for(i=0;i<=6;i++)//方法全排列
{ if(h1(s1)==h2(s2,i)&&h2(s2,i)==h3(s3,i))
{ cout<<h1(s1);
break;
}
if(h1(s1)==h2(s3,i)&&h2(s3,i)==h3(s2,i))
{ cout<<h1(s1);
break;
}
if(h1(s2)==h2(s1,i)&&h2(s1,i)==h3(s3,i))
{ cout<<h1(s2);
break;
}
if(h1(s2)==h2(s3,i)&&h2(s3,i)==h3(s1,i))
{ cout<<h1(s2);
break;
}
if(h1(s3)==h2(s1,i)&&h2(s1,i)==h3(s2,i))
{ cout<<h1(s3);
break;
}
if(h1(s3)==h2(s2,i)&&h2(s2,i)==h3(s1,i))
{ cout<<h1(s3);
break;
}
}}
-
02019-06-16 15:21:37@
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;string dao(string x,int n){
string ans(n, '0');
int i,j;
for( i=0,j=x.length()-1;i<x.length();i++,j--){
ans[i]=x[j];
}
return ans;
}int main(){
int n;
cin>>n;
string a,b,c;
cin>>a>>b>>c;
if((a[0]-dao(b,n)[0]+c[0]-dao(b,n)[0])%26==0){
cout<<dao(b,n);
}else if((a[0]-dao(c,n)[0]+b[0]-dao(c,n)[0])%26==0){
cout<<dao(c,n);
}else if((b[0]-dao(a,n)[0]+c[0]-dao(a,n)[0])%26==0){
cout<<dao(a,n);
}
} -
02018-09-07 18:29:55@
#include<iostream>
#include<string>
using namespace std;
string all("abcdefghijklmnopqrstuvwxyz");
string zb(int p,string q,int n) {
for(int i=0; i<n; i++) {
int x=all.find(q[i]);
x=(x+p+26)%26;
q[i]=all[x];
}
return q;
}
string dd(string o,int n) {
for(int i=1; i<=n/2; i++) {
char t=o[i-1];
o[i-1]=o[n-i];
o[n-i]=t;
}
return o;
}
int main() {
string a,b,c,temp;
int n,k;
cin>>n;
getline(cin,temp);
getline(cin,a);
getline(cin,b);
getline(cin,c);
for(k=0; k<=6; k++) {
if((zb(k,dd(a,n),n)==b&&zb(-k,dd(a,n),n)==c)||(zb(k,dd(a,n),n)==c&&zb(-k,dd(a,n),n)==b)){cout<<dd(a,n);k=k+7;}
else if((zb(k,dd(b,n),n)==a&&zb(-k,dd(b,n),n)==c)||(zb(k,dd(b,n),n)==c&&zb(-k,dd(b,n),n)==a)){cout<<dd(b,n);k=k+7;}
else if((zb(k,dd(c,n),n)==b&&zb(-k,dd(c,n),n)==a)||(zb(k,dd(c,n),n)==a&&zb(-k,dd(c,n),n)==b)){cout<<dd(c,n);k=k+7;}
}
return 0;
} -
02018-05-25 15:11:01@
#include<iostream> #include<cstdio> using namespace std; const int MAXN=10000+50; char str[4][MAXN]; int d1[4]= {0,1,1,2}; int d2[4]= {0,2,3,3}; int d3[4]= {0,3,2,1}; int n; bool ok(char a[],char b[],int f) { for(int i=0; i<n; i++) { char x; if(a[i]+f<'a')x='z'+f+a[i]-'a'+1; else if(a[i]+f>'z')x=a[i]+f-'z'+'a'-1; else x=a[i]+f; if(x!=b[n-i-1])return false; } return true; } int main() { scanf("%d",&n); scanf("%s%s%s",str[1],str[2],str[3]); for(int i=1; i<=3; i++) { for(int k=0; k<=6; k++) { if(ok(str[d1[i]],str[d3[i]],-k)&&ok(str[d2[i]],str[d3[i]],k)) { for(int j=n-1; j>=0; j--) { printf("%c",str[d3[i]][j]); } return 0; } if(ok(str[d1[i]],str[d3[i]],k)&&ok(str[d2[i]],str[d3[i]],-k)) { for(int j=n-1; j>=0; j--) { printf("%c",str[d3[i]][j]); } return 0; } } } return 0; }
-
02018-02-20 16:23:37@
#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>using namespace std;
bool decideStr(string a,string b){
if(a == b){
return true;
}
else return false;
}char frontChar(char c){
if(c == 'a'){
return 'z';
}
else{
return c - 1;
}
}char backChar(char c){
if(c == 'z'){
return 'a';
}
else{
return c + 1;
}
}string getStr(string a,string b){
string ans;
int len = a.size();
int leng = 0;
for(int i = 0; i < len ; i++){
leng = ans.size();
char f = a[i];
char n = b[i];
int tryT = 0;
while(tryT < 7){
if(f == n){
ans = ans + f;
break;
}
else{
f = frontChar(f);
n = backChar(n);
tryT++;
}
}
if(leng != ans.size()){
continue;
}
tryT = 0;
f = a[i];
n = b[i];
while(tryT < 7){
if(f == n){
ans = ans + f;
break;
}
else{
f = backChar(f);
n = frontChar(n);
tryT++;
}
}
}
return ans;
}string turnStr(string a){
string ans;
deque<char> que;
int len = a.size();
for(int i = 0;i < len;i ++){
char temp = a[i];
que.push_back(temp);
}
while(!que.empty()){
ans = ans + que.back();
que.pop_back();
}
return ans;
}int main(){
int meishayong;
cin >> meishayong;
string one,two,three;
cin >> one >> two >> three;
if(decideStr(turnStr(one),getStr(two,three))){
cout << turnStr(one) << endl;
}
else if(decideStr(turnStr(two),getStr(one,three))){
cout << turnStr(two) << endl;
}
else if(decideStr(turnStr(three),getStr(one,two))){
cout << turnStr(three) << endl;
}
return 0;
} -
02017-11-22 17:32:09@
#include <cstdio> #include <cstring> #include <algorithm> #include <functional> using namespace std; using namespace placeholders; const int maxN = 1e4 + 5; char encStr[3][maxN]; char transStr[3][maxN]; int len; void reverseStr(int srcIdx) { reverse_copy(encStr[srcIdx], encStr[srcIdx] + len, transStr[0]); } void forwardStr(int srcIdx, int destIdx, int step) { transform(encStr[srcIdx], encStr[srcIdx] + len, transStr[destIdx], [&] (char ch) -> char { return (ch - 'a' + step + 26) % 26 + 'a'; }); } void input() { scanf("%d", &len); for (int i = 0; i < 3; i++) scanf("%s", encStr[i]); } void solve() { int idx[] = { 0, 1, 2 }; for (int i = 0; i < 6; i++) { for (int step = 0; step <= 6; step++) { function<void(void)> funcs[] = { bind(reverseStr, idx[0]), bind(forwardStr, idx[1], 1, step), bind(forwardStr, idx[2], 2, -step) }; for (auto& fn: funcs) fn(); if (strcmp(transStr[0], transStr[1]) == 0 && strcmp(transStr[1], transStr[2]) == 0) { printf("%s", transStr[0]); return; } } next_permutation(idx, idx + 3); } } int main() { input(); solve(); return 0; }
暴力枚举即可(顺便测试一下C++11的新特性)
-
02017-10-24 20:16:13@
n=int(raw_input()) s="zabcdefghijklmnopqrstuvwxyz" s1=raw_input() s2=raw_input() s3=raw_input() def sol(ss1,ss2,ss3): ans_temp="" ans_temp2="" ans_temp3="" for i in range(n): ans_temp=ans_temp+ss1[n-i-1] for k in range(7): ans_temp2="" ans_temp3="" for i in range(n): ans_temp2=ans_temp2+s[((ord(ss2[i])-96-k+26)%26)] ans_temp3=ans_temp3+s[((ord(ss3[i])-96+k+26)%26)] if (ans_temp==ans_temp2) and (ans_temp==ans_temp3): print ans_temp exit() sol(s1,s2,s3) sol(s1,s3,s2) sol(s2,s1,s3) sol(s2,s3,s1) sol(s3,s1,s2) sol(s3,s2,s1)
-
02017-09-25 15:40:45@
代码很长,比较容易。
#include<iostream> using namespace std; int n; string a, b, c; string change(string s, int offset, int to); string swap2(string s); bool check(string a, string b, string c); int main() { cin >> n; cin >> a; cin >> b; cin >> c; if (check(a, b, c)) { } else if (check(a, c, b)) { } else if (check(b, a, c)) { } else if (check(b, c, a)) { } else if (check(c, a, b)) { } else if (check(c, b, a)) { } return 0; } bool check(string a, string b, string c) { string a1, b1, c1; a1 = swap2(a); for (int k = 0; k <= 6; k++) { b1 = change(b, k, -1); c1 = change(c, k, 1); if (a1 == b1 && b1 == c1 && a1 == c1) { cout << a1 << "\n"; return true; } } return false; } string swap2(string s) { string t = s; for (int i = 0; i < n; i++) t[i] = s[n - 1 - i]; return t; } string change(string s, int offset, int to) { string t = s; if (offset != 0) { for (int i = 0; i < n; i++) { int j = offset; while (j) { t[i] = t[i] + to; if (t[i] > 'z') { t[i] = 'a'; } if (t[i] < 'a') { t[i] = 'z'; } j--; } } } return t; }
-
02017-05-17 20:21:33@
int main()
{
int N;
string String[3];
cin >> N;
for (int i = 0; i < 3; i++){
cin >> String[i] ;
}for (int i = 0; i < 3; i++){
int u = (String[(i + 1) % 3][0] + String[(i + 2) % 3][0] - String[i][N - 1 - 0] - String[i][N - 1 - 0]) % 26;
if ((u > 6) || (u < -6)){
continue;
}
for (int ii = 1; ii < N; ii++){
if (u != (String[(i + 1) % 3][ii] + String[(i + 2) % 3][ii] - String[i][N - 1 - ii] - String[i][N - 1 - ii]) % 26){
u = -9999;
break;
}
}
if (-9999 != u){
reverse(String[i].begin(), String[i].end());
cout << String[i];
break;
}
}
return 0;
} -
02017-05-07 14:18:34@
#include<iostream>
using namespace std;int judge(char* s1,char* s2,char* s3,int n)
{
char *s_new = new char[n];
for (int i = 0;i<=n/2;i++)
{
s_new[i] = s1[n-i-1];
s_new[n-i-1] = s1[i];
}
int flag = 0;
for(int i = 0;i<n;i++)
{
if(s2[i]-s3[i]>12 && flag != -1)
{
flag = 1;
if('z'-s2[i]<=s3[i]-'a'){
if(s_new[i]!=(s2[i]+s3[i]-26)/2)
return 0;
}else{
if(s_new[i]!=(s2[i]+s3[i]+26)/2)
return 0;
}
}else if(s2[i]-s3[i]<-12 && flag != 1){
flag = -1;
if('z'-s3[i]<=s2[i]-'a'){
if(s_new[i]!=(s2[i]+s3[i]-26)/2)
return 0;
}else{
if(s_new[i]!=(s2[i]+s3[i]+26)/2)
return 0;
}
}else if(s2[i]-s3[i]<=12 && s2[i]-s3[i]>=-12){
if(s_new[i]!=(s2[i]+s3[i])/2)
return 0;
}else{
return 0;
}
}
return 1;
}void reverse(char* s,int n)
{
for(int i = 0;i<n;i++)
{
cout<<s[n-i-1];
}
return;
}int main()
{
//Read
int n;
cin>>n;
char* s1 = new char[n];
char* s2 = new char[n];
char* s3 = new char[n];
cin>>s1>>s2>>s3;//Count
if(judge(s1,s2,s3,n))
{
reverse(s1,n);
}else if(judge(s2,s1,s3,n)){
reverse(s2,n);
}else if(judge(s3,s1,s2,n)){
reverse(s3,n);
}else{
cout<<"No anwser"<<endl;
}
return 0;
} -
02017-05-06 17:45:35@
#include <iostream>
#include <cstdio>
#include <string.h>
#include <cmath>
using namespace std;
const int maxn = 10010;
char a[maxn];
char b[maxn];
char c[maxn];
bool fun(int t,int a,int b){
if(((a+b)-2*t)%26==0)
return false;
return true;
}
int main(){
int n;
scanf("%d",&n);
scanf("%s%s%s",a,b,c);
int t1,t2,t3,t,a1,a2,a3;
t1 = t2 = t3 = 1;
for(int i=0;i<n;++i){
a1 = a[i] - 'a';
a2 = b[i] - 'a';
a3 = c[i] - 'a';
if(t1){
t = a[n-i-1] - 'a';
// cout<<t<<" "<<a2<<" "<<a3<<endl;
if(fun(t,a2,a3)){
t1 = 0;
}
// cout<<t1<<endl;
}
if(t2){
t = b[n-i-1] - 'a';
// cout<<t<<" "<<a1<<" "<<a3<<endl;
if(fun(t,a1,a3)){
t2 = 0;
}
// cout<<t2<<endl;
}
if(t3){
t = c[n-i-1] - 'a';
// cout<<t<<" "<<a2<<" "<<a1<<endl;
if(fun(t,a2,a1)){
t3 = 0;
}
// cout<<t3<<endl;
}
if(t1+t2+t3==1)
break;
}
if(t1==1){
for(int i=n-1;i>=0;--i)
cout<<a[i];
}else if(t2==1){
for(int i=n-1;i>=0;--i)
cout<<b[i];
}else{
for(int i=n-1;i>=0;--i)
cout<<c[i];
}
cout<<endl;return 0;
} -
02017-02-19 21:48:04@
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<set>
#include<stack>
#include<sstream>
#include<map>
#include<vector>
#include<queue>
using namespace std;
const int N=10010;
char a1[N],a2[N],a3[N];
int length;
void reverse(char *c,int n){
int i=0,j=n-1;
while(i<j)
{
swap(c[i],c[j]);
i++;j--;
}
}void change(char *c,int n,int k){
for(int i=0;i<n;i++)
{
if(c[i]+k>'z') c[i]=c[i]+k-26;
else if(c[i]+k<'a') c[i]=c[i]+k+26;
else c[i]+=k;
}
}
void sl(char *a,char *b,char *c)
{
reverse(a,length);
for(int k=0;k<=6;k++)
{
change(b,length,k);
change(c,length,-k);
if(!strcmp(b,c)&&!strcmp(a,c))
{cout<<a<<endl;exit(0);}
change(b,length,-2*k);
change(c,length,2*k);
if(!strcmp(b,c)&&!strcmp(a,c))
{cout<<a<<endl;exit(0);}
change(b,length,k);
change(c,length,-k);
}
reverse(a,length);
}
int main(){
cin>>length;
scanf("%s%s%s",a1,a2,a3);
sl(a1,a2,a3);
sl(a2,a3,a1);
sl(a3,a2,a1);
return 0;
} -
02017-01-24 09:23:01@
var
a,b,c,s:ansistring;
n,i:longint;
begin
readln(n);readln(a);readln(b);readln(c);
if (ord(a[1])+ord(b[1])-2*ord(c[n]))mod 26=0 then s:=c
else if (ord(a[1])+ord(c[1])-2*ord(b[n]))mod 26=0 then s:=b
else s:=a;
for i:=n downto 1 do write(s[i]);
end. -
02017-01-19 11:27:00@
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
string sw(string s2)
{
string s1="";
for(int i=0;i<s2.size();i++)
{
s1=s2[i]+s1;
}
return s1;
}
bool bd(string s3,string s4,int k)
{
for(int i=0;i<s4.size();i++)
{
if(s4[i]-k>='a'){if ((s4[i]-k)!=s3[i])return 0;}
else
{if((s4[i]-k+26)!=s3[i])return 0;}
}
return 1;
}bool bg(string s3,string s4,int k)
{
for(int i=0;i<s4.size();i++)
{
if(s4[i]+k<='z'){if ((s4[i]+k)!=s3[i])return 0;}
else
{if((s4[i]+k-26)!=s3[i])return 0;}
}
return 1;
}int main()
{
string sf,sc,st,s1,s2,s3;
int n;
scanf("%d",&n);
cin>>sf>>sc>>st;
s1=sw(sf);
s2=sw(sc);
s3=sw(st);
for(int k=0;k<=6;k++)
{
if((bd(s1,sc,k)&&bg(s1,st,k))||(bd(s1,st,k)&&bg(s1,sc,k))){cout<<s1<<"\n";break;}
if((bd(s2,sf,k)&&bg(s2,st,k))||(bd(s2,st,k)&&bg(s2,sf,k))){cout<<s2<<"\n";break;}
if((bd(s3,sf,k)&&bg(s3,sc,k))||(bd(s3,sc,k)&&bg(s3,sf,k))){cout<<s3<<"\n";break;}
}
return 0;
} -
02016-10-26 18:59:59@
#include<iostream> #include<algorithm> using namespace std; char s1[5][12000],s2[5][12000]; int n; void case1(int x){ for(int j=1;j<=n;j++) s2[x][j]=s1[x][j]; for(int i=1;i<=n/2;i++){ swap(s2[x][i],s2[x][n-i+1]); } } void case2(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 case3(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<7;k++) for(int i=0;i<3;i++){ case1(i+1); case2((i+1)%3+1,k); case3((i+2)%3+1,k); if(ok())return; case3((i+1)%3+1,k); case2((i+2)%3+1,k); if(ok())return; } } int main(){ ios::sync_with_stdio(false); cin>>n; for(int i=1;i<4;i++) for(int j=1;j<=n;j++) cin>>s1[i][j]; solve(); for(int i=1;i<=n;i++)cout<<s2[1][i]; cout<<endl; return 0; }