暑假练习赛 007 B - Weird Cryptography

Weird Cryptography

Description

standard input/output
Statements

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.

Sample Input

 
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

Sample Output

 

Hint

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.

/*
将单词放进set中会返回一个数,给出n个单词,任意放进set中,让你求返回的数字组成最小数字

思路:先排序,第一次,全放,然后每种个数减一,再放进去,再每种个数减一,以此类推,得出第i大的数字
*/
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#include<map>
#define N 10010
using namespace std;
bool cmp(int s1,int s2)
{
    if(s1>s2)
        return true;
    return false;
}
vector<string >v;
int ans[N];
int n;
string s;
int cur[N];
int main()
{
    //freopen("in.txt","r",stdin);
    int p=1;
    while(true)
    {
        v.clear();
        int len=1;
        scanf("%d",&n);
        memset(ans,0,sizeof ans);
        memset(cur,0,sizeof cur);
        if(!n) break;
        //for(int i=0;i<=n;i++)
        //    cout<<ans[i]<<" ";
        //cout<<endl;
        for(int i=0;i<n;i++)
        {
            cin>>s;
            v.push_back(s);
        }
        sort(v.begin(),v.end());
        //cout<<"ok"<<endl;
        for(int i=0;i<n-1;i++)
        {
            if(v[i]==v[i+1])
                ans[len]++;
            else
                ans[len++]++;
        }
        if(v[n-1]==v[n-2])
            ans[len]++;
        else
            ans[++len]++;
        int maxn=-1;
        for(int i=1;i<=len;i++)
        {
            if(maxn<ans[i])
                maxn=ans[i];
            for(int j=0;j<ans[i];j++)
                cur[j]++;
        }
        //cout<<"len="<<len<<endl;
        //for(int i=0;i<=len;i++)
        //    cout<<ans[i]<<" ";
        //cout<<endl;
        //cout<<"len="<<len<<endl;
        printf("Case %d: ",p++);
        for(int i=maxn-1;i>=0;i--)
            printf("%d",cur[i]);
        printf("\n");
        //cout<<endl;
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/5800962.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"text/plain;charset=UTF-8" 是一个Content-Type的标识,用于指定请求或响应的内容类型。在引用和中提到的问题中,"text/plain;charset=UTF-8" 表示请求中的内容类型不受支持或响应中的内容类型不正确。 通常,"text/plain;charset=UTF-8" 表示纯文本内容,使用UTF-8编码。如果您在使用Postman发送POST请求时遇到此错误消息,可能是因为您没有正确设置请求的头部信息或请求体的内容类型。 要解决此问题,您可以尝试以下几种方法: 1. 在Postman中,确保您设置了正确的请求头部信息。您可以在请求头中添加"Content-Type: text/plain;charset=UTF-8",以指定请求的内容类型。 2. 检查您的请求体内容是否符合"text/plain;charset=UTF-8" 的格式要求。确保您正在发送的是纯文本,并使用UTF-8编码。 3. 如果您正在与某个API进行通信,请参考API文档,查看它所需的正确的内容类型。 需要注意的是,具体的解决方法可能因您的具体情况而有所不同。如果以上方法无法解决您的问题,建议您查看Postman的文档或联系API的提供方以获取更具体的帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Content type ‘text/plain;charset=UTF-8‘ not supported](https://blog.csdn.net/SmartYG/article/details/124824940)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [weird-text](https://download.csdn.net/download/weixin_42097450/15884138)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [RestTemplate远程调用,响应结果中的响应头为content-type:text/plain;charset=utf-8,且数据类型转换失败](https://blog.csdn.net/Staba/article/details/124442200)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值