Editorial for Chat chit


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 flashmt

const a:array[1..13] of string[3]=('k','ko','ng','n','dc','hok','ntn','kq','j','w','f','dz','z');
      b:array[1..13] of string[11]=('khong','khong','nguoi','nhieu','duoc','khong','nhu the nao',
      'ket qua','gi','qu','ph','d','d');
var s,s1:string;
    i,j:byte;
    c1,c2:char;

begin
     read(s);
     for i:=1 to 13 do
     begin
          s1:=s;
          j:=pos(a[i],s1);
          while j<>0 do
          begin
               c1:=s[j+length(a[i])]; c2:=s[j-1];
               if ((ord(c1)<97) or (ord(c1)>122)) and ((ord(c2)<97) or (ord(c2)>122)) or (i>8) then
               begin
                    delete(s,j,length(a[i]));
                    insert(b[i],s,j);
                    delete(s1,j,length(a[i]));
                    insert(b[i],s1,j);
               end
               else s1[j]:='z';
               j:=pos(a[i],s1);
          end;
     end;
     write(s);
end.

Code mẫu của happyboy99x

#include <bits/stdc++.h>
using namespace std;

int main(){
    string str;
    getline(cin, str);
    str.insert(0, " ");
    str.insert(str.length(), " ");
    for (unsigned int i=1; i<str.length(); ++i){
        if (str[i] == 'k' && str[i-1] == ' ' && str[i+1] == ' ')
            str.replace(i, 1 , "khong");
        if (str[i] == 'k' && str[i-1] == ' ' && str[i+1] == 'o' && str[i+2] == ' ')
            str.replace(i, 2 , "khong");
        if (str[i] == 'n' && str[i-1] == ' ' && str[i+1] == ' ')
            str.replace(i, 1 , "nhieu");
        if (str[i] == 'n' && str[i-1] == ' ' && str[i+1] == 'g' && str[i+2] == ' ')
            str.replace(i, 2 , "nguoi");
        if (str[i] == 'd' && str[i-1] == ' ' && str[i+1] == 'c' && str[i+2] == ' ')
            str.replace(i, 2 , "duoc");
        if (str[i] == 'h' && str[i-1] == ' ' && str[i+1] == 'o' && str[i+2] == 'k' && str[i+3] == ' ')
            str.replace(i, 3 , "khong");
        if (str[i] == 'n' && str[i-1] == ' ' && str[i+1] == 't' && str[i+2] == 'n' && str[i+3] == ' ')
            str.replace(i, 3 , "nhu the nao");
        if (str[i] == 'k' && str[i-1] == ' ' && str[i+1] == 'q' && str[i+2] == ' ')
            str.replace(i, 2 , "ket qua");
        if (str[i] == 'j')
            str.replace(i, 1 , "gi");
        if (str[i] == 'w')
            str.replace(i, 1 , "qu");
        if (str[i] == 'f')
            str.replace(i, 1 , "ph");
        if (str[i] == 'd' && str[i+1] == 'z')
            str.replace(i, 2 , "d");
        if (str[i] == 'z')
            str.replace(i, 1 , "d");
    }
    for (unsigned int i=1; i<str.length() - 1; ++i)
        cout << str[i];
}

Code mẫu của ladpro98

program chatchit;
uses    math;
const   fi='';
var     res:ansistring;

procedure rw(x,y:string);
var     i:longint;
        t:ansistring;
begin
        t:='';
        i:=1;
        while i<=length(res) do
        begin
        if res[i] in ['a'..'z'] then
                t:=t+res[i]
        else
        if (i+length(x)<length(res)) and not (res[i+length(x)+1] in ['a'..'z']) and (copy(res,i+1,length(x))=x) then
                begin
                        t:=t+res[i]+y;
                        inc(i,length(x));
                end
                else
                t:=t+res[i];
        inc(i);
        end;
        res:=t;
end;

procedure r(x,y:string);
var     i:longint;
        t:ansistring;
begin
        i:=1;
        t:='';
        while i<=length(res) do
        begin
        if copy(res,i,length(x))=x then
        begin
                t:=t+y;
                inc(i,length(x)-1);
        end
        else t:=t+res[i];
        inc(i);
        end;
        res:=t;
end;

procedure input;
var     inp:text;
begin
        assign(inp,fi);
        reset(inp);
        readln(inp,res);
        close(inp);
end;

begin
        input;
        res:=' '+res+' ';
        rw('k','khong');
        rw('ko','khong');
        rw('ng','nguoi');
        rw('n','nhieu');
        rw('dc','duoc');
        rw('hok','khong');
        rw('ntn','nhu the nao');
        rw('kq','ket qua');
        r('j','gi');
        r('w','qu');
        r('f','ph');
        r('dz','d');
        r('z','d');
        write(copy(res,2,length(res)-1));
end.

Code mẫu của khuc_tuan

#include <string>
#include <iostream>
#include <map>

using namespace std;

map<string,string> RW, R;

void init() {
RW["k"]="khong";
RW["ko"]="khong";
RW["ng"]="nguoi";
RW["n"]="nhieu";
RW["dc"]="duoc";
RW["hok"]="khong";
RW["ntn"]="nhu the nao";
RW["kq"]="ket qua";
R["j"]="gi";
R["w"]="qu";
R["f"]="ph";
R["dz"]="d";
R["z"]="d";
}


int  main() {
    init();
    string s;
    getline( cin, s);
    bool tiep = true;
    while(tiep) {
        tiep = false;
        for(int i=0;i<s.length();++i) if(islower( s[i])) {
            int st = i;
            int en = i;
            while(st>0 && islower(s[st-1])) --st;
            while(en<(int)s.length()-1 && islower(s[en+1])) ++en;
            string w = s.substr( st, en-st+1);
            if(RW.count(w)) {
                tiep = true;
                s.replace( st, en-st+1, RW[w]);
                break;
            }
        }
    }
    //cout << s << endl;
    tiep = true;
    while(tiep) {
        tiep = false;
        for(int i=0;i<(int)s.length()-1;++i) if(R.count(string("")+s[i] + s[i+1])) {
            tiep = true;
            //cout << s << endl;
            s.replace( i, 2, R[string("")+s[i]+ s[i+1]]);
            //cout << " sau : " << s << endl;
            break;
        }
        for(int i=0;i<s.length();++i) if(R.count(string("")+s[i])) {
            tiep = true;
            s.replace( i, 1, R[string("")+s[i]]);
            break;
        }

    }
    cout << s << endl;
    //system("pause");
    return 0;
}

Comments

Please read the guidelines before commenting.


There are no comments at the moment.