Problem Statement

Alice has a string s of lowercase letters. The string is written on a wall.

Alice also has a set of cards. Each card contains a single letter. Alice can take any card and glue it on top of one of the letters of s. She may use any subset of cards in this way, possibly none or all of them. She is not allowed to glue new letters in front of s or after s, she can only replace the existing letters.

Alice wants to produce the lexicographically largest possible string.

You are given the string s. You are also given a string t. Each character of t is a letter written on one of the cards. Compute and return the lexicographically largest string Alice can produce on the wall while following the rules described above.

Definition

Class:

LexmaxReplace

Method:

get

Parameters:

string, string

Returns:

string

Method signature:

string get(string s, string t)

(be sure your method is public)

Limits

Time limit (s):

2.000

Memory limit (MB):

512

Stack limit (MB):

512

Notes

Given two distinct strings X and Y of the same length, the lexicographically larger one is the one that has a larger character on the first position on which they differ.

Constraints

s will contain between 1 and 50 characters, inclusive.

t will contain between 1 and 50 characters, inclusive.

s will contain only lowercase English letters (‘a’ - ‘z’).

t will contain only lowercase English letters (‘a’ - ‘z’).

Examples

0)

“abb”

“c”

Returns: “cbb”

Alice has a single card. This card contains the letter ‘c’. The optimal solution is to glue it on top of s[0], producing the string “cbb”.

1)

“z”

“f”

Returns: “z”

Here the optimal solution is to do nothing. The card with the letter ‘f’ will remain unused.

2)

“fedcba”

“ee”

Returns: “feeeba”

3)

“top”

“coder”

Returns: “trp”

4)

“xldyzmsrrwzwaofkcxwehgvtrsximxgdqrhjthkgfucrjdvwlr”

“xfpidmmilhdfzypbguentqcojivertdhshstkcysydgcwuwhlk”

Returns: “zyyyzyxwwwzwvuuttxwtssvtssxrqxppqrontmmllukrkjvwlr”

【题目链接】:

【题意】



你有最多50个字符集合,

每个字符最多只能用一次;

(所有字符只包含小写字母)

然后给你一个字符串s;

让你使用这个字符集合里面的字符,去代替字符串s的每一位,使得这个字符串s的字典序达到最大;

【题解】



顺序枚举每一位,对于每一位,找一找有没有比这个字母的字典序大的字符,有的话,就用那个代替这一位上面的字母;

没有就跳过;



【Number Of WA】



0



【反思】



比较明显的题。



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110;
//head map <char,int> dic; class LexmaxReplace
{
public:
string get(string s, string t)
{
rep1(i,0,(int) t.size()-1){
dic[t[i]]++;
}
rep1(i,0,(int) s.size()-1){
for (char key = 'z';key>=s[i]+1;key--)
if (dic[key]>0){
dic[key]--;
s[i] = key;
break;
}
}
return s;
}
};

最新文章

  1. c++嵌套类-内存分配
  2. JQuery 操作按钮遮罩(删除)
  3. elk是指logstash,elasticsearch,kibana三件套,这三件套可以组成日志分析和监控工具
  4. Prism&amp;MEF构建开发框架
  5. BITED数学建模七日谈之七:临近比赛时的准备工作
  6. 新工程软连接到原来的工程的out目录后,可以直接编译模块
  7. C#中Delegate
  8. 分享一个字数限制和统计的UITextView分类方法
  9. mysql 数据库 备份 还原
  10. html 表单初步学习
  11. 前端部署ant+yuicompressor文件压缩+获取版本+SSH公布(部分代码)
  12. PHP中的Define和Const区别
  13. 总结-Linux
  14. Linux---一级/二级目录以及位置目录名/指令
  15. css3整理--background-origin
  16. mysql的导入导出工具mysqldump命令详解
  17. 第 4 章—— C# 语言特性(《精通 ASP.NET MVC 5》)
  18. 监测代码执行时间之Stopwatch
  19. java学习笔记—第三方数据库连接池包1(29)
  20. SQL 去重 显示第一条数据 显示一条数据

热门文章

  1. sublime text3前端常用插件
  2. 3ds Max实例教程-顽皮的小孩
  3. vue生命周期-学习心得
  4. size(A,1)
  5. Python学习第一天-编写登陆接口
  6. CentOS6.5安装redis(3.0.3)
  7. Qt之字典划词
  8. SJTU 1319. countColors
  9. Homebrew命令具体解释
  10. linux系统调用表(system call table)