Problem F. String
Input file: standard input
Output file: standard output
Time limit: 1 seconds Memory limit: 128 megabytes
大家都知道馬大佬很皮
馬大佬很喜歡 ICPC,馬大佬現在手里有 n 塊積木,每一個積木是 a 到 z,26 個英文字母 中的一個,現在馬大佬想用這些積木組成盡可能多的 acmicpc,問你能組成多少個
Input
輸入第一行一個整數 T,代表接下來有 T 組測驗資料 接下來 T 行,每一行先輸入一個整數 n,代表積木的數量
接下來輸入一個長度為 n 的字串,代表每一個積木的英文字母 資料保證只有小寫字母
1 <= T <= 10,1 <= n <= 100000
Output
對于每一組測驗資料,輸出對應答案
Example
|
standard input |
standard output |
|
1 8 aacmicpc |
1 |
#include<iostream> #include<cmath> #include<cstring> #define N 100000 using namespace std; int main() { char str[N]; int t; cin >> t; while(t--) { int n; int num; int a = 0,c = 0,i = 0,m = 0,p = 0,flag = 0; cin >> n >> str; for(int j = 0;j < n;j++) { if(str[j] == 'a') a++; if(str[j] == 'c') c++; if(str[j] == 'i') i++; if(str[j] == 'm') m++; if(str[j] == 'p') p++; } num = min(a,i); num = min(num,m); num = min(num,p); num = min(num,c/3); // cout << a << " " << c << " " << i << " " << m << " " << p << endl; cout << num << endl; } return 0; }
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/96293.html
標籤:C++
