Codeforces Round #586 (Div. 1 + Div. 2) A. Cards
链接:
https://codeforces.com/contest/1220/problem/A
题意:
When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately and shuffled them because he wasn't yet able to read. His father decided to rearrange them. Help him restore the original number, on condition that it was the maximum possible one.
思路:
优先找1, 再找0
代码:
#include <bits/stdc++.h>
using namespace std;
map<char, int> Mp;
int main()
{
int n;
char c;
cin >> n;
for (int i = 1;i <= n;i++)
{
cin >> c;
Mp[c]++;
}
int one = min(Mp['o'], min(Mp['n'], Mp['e']));
Mp['o'] -= one, Mp['n'] -= one, Mp['e'] -= one;
int zero = min(Mp['z'], min(Mp['e'], min(Mp['r'], Mp['o'])));
for (int i = 1;i <= one;i++)
cout << 1 << ' ' ;
for (int i = 1;i <= zero;i++)
cout << 0 << ' ' ;
cout << endl;
return 0;
}