Editorial for Sức mạnh của ngôn từ


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<cstring>
#include<algorithm>
#include<cctype>
using namespace std;

char s[1002][1002], g[102][32];
int n, m, ls[1002], lg[102];

void enter() {
    scanf("%d%d", &n, &m);
    for(int i = 0; i < n; ++i) {
        scanf("%s%n", s[i], ls+i);
        for(int j = 0; j < ls[i]; ++j) if(s[i][j] >= 0x41 && s[i][j] <= 0x5a) s[i][j] += 0x20;
    }
    for(int i = 0; i < m; ++i) {
        scanf("%s%n", g[i], lg+i);
        for(int j = 0; j < lg[i]; ++j) if(g[i][j] >= 0x41 && g[i][j] <= 0x5a) g[i][j] += 0x20;
    }
}

void solve() {
    for(int i = 0; i < n; ++i) {
        int res = 0;
        for(int j = 0; j < m; ++j)
            for(int x = 0, y = 0; x < ls[i]; ++x)
                if(s[i][x] == g[j][y]) if(++y == lg[j]) { ++res; break; }
        printf("%d\n", res);
    }
}

int main() {
    enter();
    solve();
    return 0;
}

Code mẫu của RR

//Written by RR

{$MODE OBJFPC}

uses math;
const
  FINP          =       '';
  FOUT          =       '';
  MAXN          =       1011;

var
  f1,f2         :       text;
  m,n           :       longint;
  a             :       array[1..MAXN] of ansistring;
  b             :       array[1..MAXN] of string[31];
  stack         :       array['A'..'Z',1..MAXN] of longint;
  top,now       :       array['A'..'Z'] of longint;

procedure openF;
    begin
      assign(f1,FINP); reset(f1);
      assign(f2,FOUT); rewrite(f2);
    end;

procedure closeF;
    begin
      close(f1);
      close(f2);
    end;

procedure inp;
    var
      i,j:longint;
    begin
      readln(f1,m,n);
      for i:=1 to m do
        begin
          readln(f1,a[i]);
          for j:=length(a[i]) downto 1 do
            a[i,j]:=upcase(a[i,j]);
        end;
      for i:=1 to n do
        begin
          readln(f1,b[i]);
          for j:=length(b[i]) downto 1 do
            b[i,j]:=upcase(b[i,j]);
        end;
    end;

procedure solve;
    var
      i,j,res,k,u:longint;
      c:char;
      ok:boolean;
    begin
      for i:=1 to m do
        begin
          res:=0;
          fillchar(top,sizeof(top),0);
          for j:=1 to length(a[i]) do
            begin
              c:=a[i,j];
              inc(top[c]);
              stack[c,top[c]]:=j;
            end;

          u:=0;
          for k:=1 to n do
            begin
              for c:='A' to 'Z' do now[c]:=1;
              ok:=true;
              u:=0;
              for j:=1 to length(b[k]) do
                begin
                  c:=b[k,j];
                  while (now[c]<=top[c]) and (stack[c,now[c]]<=u) do inc(now[c]);
                  if (now[c]>top[c]) then
                    begin
                      ok:=false;
                      break;
                    end;
                  u:=stack[c,now[c]];
                end;
              if ok then inc(res);
            end;
          writeln(f2,res);
        end;
    end;

begin
  openF;
  inp;
  solve;
  closeF;
end.

Code mẫu của hieult

#include <stdio.h>
#include <string.h>
#include <ctype.h>
//#include <conio.h>

int main()
{
    //freopen("WWORDPOW.in","r",stdin);
    int n,m;
    char s[1001][1001],k[100001][31];
    int ls[1001],lk[100001],x,y;
    scanf("%d %d",&n,&m);
    for(int i = 1;i<=n;i++)
    {
        scanf("%s",s[i]);
        ls[i] = strlen(s[i]);
        for(int j = 0;j<ls[i];j++)
            s[i][j] = tolower(s[i][j]);
    }
    for(int i = 1;i<=m;i++)
    {
        scanf("%s",k[i]);
        lk[i] = strlen(k[i]);
        for(int j = 0;j<=lk[i];j++)
            k[i][j] = tolower(k[i][j]);
    }
    for(int i = 1;i<=n;i++)
    {
        int KQ = 0;
        for(int j = 1;j<=m;j++)
        {
                    x=0;
            for(y=0;s[i][y];y++)
            {
                if(s[i][y]==k[j][x])
                    x++;
                if(!k[j][x]){
                    KQ++;break;
                }
            }
        }
        printf("%d\n",KQ);
    }
   // getch();
}

Comments

Please read the guidelines before commenting.


There are no comments at the moment.