Editorial for Tìm xâu


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này

Code mẫu của happyboy99x

#include<cstdio>
#include<set>
#include<string>
using namespace std;

set<string> memo;
char s[20];
int n;

int main() {
    scanf("%d", &n);
    while(n--) {
        scanf("%s", s);
        string tmp (s);
        set<string>::iterator it = memo.find(tmp);
        if(it == memo.end()) memo.insert(tmp);
        else memo.erase(it);
    }
    printf("%s\n", memo.begin()->c_str());
    return 0;
}

Code mẫu của ladpro98

program ltpmseq_xor;
var     a:array[1..15] of longint;
        s,res:string;
        n,i,j:longint;
begin
        fillchar(a,sizeof(a),0);
        readln(n);
        for i:=1 to n do
        begin
                readln(s);
                for j:=1 to length(s) do
                begin
                        a[j]:=a[j] xor ord(s[j]);
                end;

        end;
        res:='';
        for i:=1 to 15 do
        begin
                if a[i]<>0 then res:=res+chr(a[i]);
        end;
        if res<>'' then write(res)
        else write('-1');
end.

Code mẫu của RR

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <complex>

#define FOR(i,a,b) for(int i = a; i <= b; ++i)
#define FORD(i,a,b) for(int i = a; i >= b; --i)
#define REP(i,a) for(int i = 0; i < a; ++i)
#define MP make_pair
#define PB push_back

using namespace std;

char s[100], res[100];

int main() {
    int n; scanf("%d\n", &n);
    string res = "";
    int len = 0;
    while (n--) {
        gets(s);
        int l = strlen(s);
        REP(x,l) res[x] ^= s[x];
        len ^= l;
    }
    REP(x,len) cout << res[x]; cout << endl;
    return 0;
}

Code mẫu của hieult

#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<iterator>
#include<iostream>
#include<cctype>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<list>
//#include<conio.h>
#define ep 0.000000001
#define maxn 10011
#define oo 1111111111
#define modunlo 111539786
#define TR(c, it) for(typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
double const PI=4*atan(1);

using namespace std;

typedef pair<int, int> II;
typedef vector<int> VI;
typedef vector<II> VII;
typedef vector<VI> VVI;
typedef vector<VII> VVII;

char s[22],t[111111][22];
int n,l,len;

int main(){
    // freopen("input.in","r",stdin);
   //  freopen("output.out","w",stdout);
     scanf("%d",&n);
     len = 0;
     for(int i = 0;i<n;i++){
          scanf("%s",t[i]);
          l = strlen(t[i]);     
          for(int j = 0;j<l;j++) s[j]^=t[i][j];
          len >?= l;
     }
     s[len] = '\0';
     for(int i = 0;i<n;i++){
           if(strcmp(s,t[i])==0){
                 printf("%s",s);
                 return 0;
           }
     }
     printf("-1");
   //  printf("%s",s);
}

Comments

Please read the guidelines before commenting.


There are no comments at the moment.