/** Lucky Boy **/
#include <bits/stdc++.h>
#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 pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 1000006
#define maxm 500005
#define pii pair <int,int>
#define Task ""
using namespace std;
int n,m,top[26];
vector <string> s[26];
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//freopen(".inp", "r",stdin);
cin >> n >> m;
FOR(i,1,n)
{
string temp;
cin >> temp;
s[temp[0]-'a'].pb(temp);
}
FOR(i,0,25) sort(s[i].begin(),s[i].end());
while (m--)
{
char c;
int w;
cin >> c;
w = c - 'a';
cout << s[w][top[w]++] << '\n';
if (top[w] == s[w].size()) top[w] = 0;
}
}
Compilation message
zigzag.cpp: In function 'int main()':
zigzag.cpp:36:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (top[w] == s[w].size()) top[w] = 0;
~~~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
612 KB |
Output is correct |
4 |
Correct |
3 ms |
792 KB |
Output is correct |
5 |
Correct |
2 ms |
872 KB |
Output is correct |
6 |
Correct |
2 ms |
964 KB |
Output is correct |
7 |
Correct |
80 ms |
8344 KB |
Output is correct |
8 |
Correct |
83 ms |
10076 KB |
Output is correct |
9 |
Correct |
80 ms |
11696 KB |
Output is correct |
10 |
Correct |
102 ms |
13312 KB |
Output is correct |