Created
September 15, 2018 10:42
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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