Weird Cryptography Gym - 100935B 单词分组问题

Khaled was sitting in the garden under an apple tree, suddenly! , well… you should guess what happened, an apple fell on his head! , so he came up with a new Cryptography method!!
The method deals only with numbers, so… If you want to encode a number, you must represent each of its digits with a set of strings, then the size of the set is the digit itself, No set should contain the same string more than once.
For example: the number 42, can be represented with the following two sets:

  1. “dog”   “load”   “under”   “nice”.

  2. “stack”   “dog”.
    The first set contain four strings so it represent the digit 4.
    The second set contain two strings so it represent the digit 2.
    Given N strings, what is the smallest number you can get from dividing these strings into non-empty sets, and then decode the result by Khaled’s Cryptography method? , You must use all the given strings, and no set should contain the same string more than once.

     Input
     The input consists of several test cases, each test case starts with 0 < N ≤ 10000, the number of the given strings, then follows N space-separated string, each string will contain only lower-case English letters, and the length of each string will not exceeded 100.
    

You can assume that there are no more than nine distinct strings among the given strings.
A line containing the number 0 defines the end of the input you should not process this line.

    Output
    For each test case print a single line in the following format: "Case c: x"   where c is the test case number starting from 1 and x is the solution to the described problem above.

    Examples

Input

3 one two two
7 num go book go hand num num
25 aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
0

Output

Case 1: 12
Case 2: 124
Case 3: 1111111111111111111111111

    Note
    In the first sample, we divided the given strings into two sets, the first set contains two word: "one"   and "two"   so it represents the digit 2, the second set contains only one word: "two"   so it represent the digit 1.
    using namespace std;
#include<bits/stdc++.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#define LL long long
#define INF 0x3f3f3f3f
map<string,int>mp;
string s;
map <string,int> ::iterator iter;
void acc_ios()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
}
int ans[1000001];
int  main()
{
  acc_ios();
  int n;
  int cast=0;
  while(cin>>n&&n)
  {
      memset(ans,0,sizeof(ans));
      int mx=0;
      mp.clear();
      for(int i=0; i<n;i++)
      {
          cin>>s;
          mp[s]++;
          mx=max(mx,mp[s]);
          ans[mp[s]]++;
      }
      sort(ans+1,ans+1+mx);
      cout<<"Case "<<++cast<<": ";
      for(int i=1;i<=mx;i++)
      {
          cout<<ans[i];
      }
      cout<<endl;
  }
  return 0;
}

总结:当时没想到还可以这样子,单词进来的过程中不断更新各个单词数的数量,就是所得。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值