NC214204. hpytxdy
描述
输入描述
输入一个字符串,字符串长度小于1e5
输出描述
输出能组合出多少hpytxdy这个字符串
示例1
输入:
hpytxdy
输出:
1
示例2
输入:
pyhtxdyhpytxdy
输出:
2
Python3(3.9) 解法, 执行用时: 34ms, 内存消耗: 4076K, 提交时间: 2020-11-28 15:03:07
# encoding: utf-8 from math import sqrt, gcd, log10, log2 from queue import Queue from random import randint from random import shuffle from queue import Queue from decimal import getcontext, Decimal from collections import OrderedDict from collections import Counter from random import * import sys sys.setrecursionlimit(10 ** 6) if __name__ == '__main__': # sys.stdin = open('1.txt', 'r') a = input() s = Counter(a) a = [s['h'], s['p'], s['y']//2, s['t'], s['x'], s['d']] print(min(a))
C(clang11) 解法, 执行用时: 3ms, 内存消耗: 372K, 提交时间: 2020-11-28 16:01:48
#include <stdio.h> char b[100005]={0}; int main() { int a[6]={0}; scanf("%s",b); for(int i=0;b[i];i++) { if(b[i]=='h') a[0]++; if(b[i]=='p') a[1]++; if(b[i]=='y') a[2]++; if(b[i]=='t') a[3]++; if(b[i]=='x') a[4]++; if(b[i]=='d') a[5]++; } a[2]/=2; int k=0; for(int i=0;i<6;i++) if(a[k]>a[i])k=i; printf("%d",a[k]); }
C++(clang++11) 解法, 执行用时: 5ms, 内存消耗: 468K, 提交时间: 2020-11-28 15:54:57
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5+10; char c[maxn]; map <char,int>mp1; string s = "hpytxd"; int main(){ scanf("%s",c); int n = strlen(c); for(int i = 0;i < n ;++i){ mp1[c[i]]++; } int ans = 1e6; mp1['y']/=2; for(int i = 0;i<=5;++i)ans = min(ans,mp1[s[i]]); printf("%d\n",ans); return 0; }