namespace myjinxin {publicclassKata{publicintStringsConstruction(string A,string B){int diff = B.Length;foreach(var c in A){int a = A.Length - A.Replace(c.ToString(),"").Length;int b = B.Length - B.Replace(c.ToString(),"").Length;if(diff > b / a)
diff = b / a;}return diff;}}}
答案2:
namespace myjinxin {publicclassKata{publicintStringsConstruction(string A,string B ){var a =newint[26];foreach(var c in A ){
a[ c -'a']+=1;}var b =newint[26];foreach(var c in B ){
b[ c -'a']+=1;}var count =0;while(true){for(int i =0; i < a.Length; i++){
b[ i ]-= a[ i ];if( b[ i ]<0){return count;}}
count +=1;}}}}
答案3:
namespace myjinxin
{using System.Text.RegularExpressions;using System.Collections.Generic;publicclassKata{publicintStringsConstruction(string A,string B){string s = Regex.Replace(B,@"[^"+A+"]","");var dict =newDictionary<char,int>();foreach(var i in s){if(dict.ContainsKey(i))
dict[i]+=1;else
dict.Add(i,1);}int count =0;bool check =true;while(check){foreach(var i in A){if(dict.ContainsKey(i)&& dict[i]>0)
dict[i]-=1;else
check =false;}if(check)
count +=1;}return count;}}}
namespace myjinxin
{using System;using System.Linq;using System.Collections.Generic;publicclassKata{publicintStringsConstruction(string A,string B){//coding and coding..int min = Int32.MaxValue;var hashTable = A.Select(x =>newKeyValuePair<char,int>(x, A.Count(c => c == x))).Distinct();foreach(var c in hashTable){var current = B.Count(x => x == c.Key)/ c.Value;
min = current < min ? current : min;}return min;}}}
答案10:
namespace myjinxin
{using System;using System.Collections.Generic;using System.Linq;using System.Text;publicclassKata{publicintStringsConstruction(string A,string B){//coding and coding..
Dictionary<char,int> frecA = A.ToCharArray().GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());
Dictionary<char,int> frecB = B.ToCharArray().GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());int min =int.MaxValue;foreach(KeyValuePair<char,int> kvp in frecA){if(!frecB.ContainsKey(kvp.Key)){return0;}else{if(frecB[kvp.Key]>= kvp.Value){
min = Math.Min(min, frecB[kvp.Key]/ kvp.Value);}else{return0;}}}return min;}}}