Skip to content

Instantly share code, notes, and snippets.

@completejavascript
Created September 15, 2018 10:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save completejavascript/7bee9e865dc1bb2d254a45d400a0882a to your computer and use it in GitHub Desktop.
#include<iostream>
using namespace std;
const int MAX = 1000005;
const int MAX_QUERY = 55;
int L; // Số khu đất trong vườn
char S[MAX]; // Xâu đầu vào
int Q; // Số testcase
char Query[MAX_QUERY]; // Xâu querry
int MinHuman; // Số nhân công tối đa.
int Count[150]; // Kiểm tra chữ cái có xuất hiện trong querry hay không.
int main()
{
//freopen("input.txt","r",stdin);
ios::sync_with_stdio(false);
cin >> L >> S >> Q;
for(int i = 0; i < Q; i++)
{
for(int i = 0; i < 150; i++)
Count[i] = 0;
// Nhập đầu vào
MinHuman = 0;
cin >> Query;
// Đánh dấu các kí tự xuất hiện trong xâu query
int Leng = 0;
while(Query[Leng] != '\0')
{
Count[Query[Leng]] = 1;
Leng++;
}
// Duyệt từ đầu đến cuối mảng
// Tìm ra số cụm chỉ toàn các kí tự thuộc query.
int before = 0;
for(int i = 0; i < L; i++)
{
if(Count[S[i]] == 1 && before == 0)
{
MinHuman++;
before = 1;
}
else if(Count[S[i]] == 0 && before == 1)
{
before = 0;
}
}
// In kết quả
cout << MinHuman << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment