S and T are strings composed of lowercase letters. In S, no letter occurs more than once.

S was sorted in some custom order previously. We want to permute the characters of T so that they match the order that S was sorted. More specifically, if x occurs before y in S, then x should occur before y in the returned string.

Return any permutation of T (as a string) that satisfies this property.

Example :
Input:
S = "cba"
T = "abcd"
Output: "cbad"
Explanation:
"a", "b", "c" appear in S, so the order of "a", "b", "c" should be "c", "b", and "a".
Since "d" does not appear in S, it can be at any position in T. "dcba", "cdba", "cbda" are also valid outputs.

Note:

  • S has length at most 26, and no character is repeated in S.
  • T has length at most 200.
  • S and T consist of lowercase letters only.

S是一种字母的排序方式,现在让T按照S的排序方式再输出一次,在S没有出现的字母就随便排,S不会出现相同字母

首先T和S都出现的字母,我们按照S的字母出现位置放进新的字符串里,然后呢,没出现的放最后,再然后就是把空的位置去掉就好了。

 class Solution {
public:
map<char,int>Mp,mp;
string customSortString(string S, string T) {
string Str="";
string Ctr="";
int lens=S.length();
int lent=T.length();
for(int i=;i<max(lent,lens);i++){
Str+='#';
}
for(int i=;i<lens;i++){
Mp[S[i]]=i+;
}
for(int i=;i<lent;i++){
mp[T[i]]++;
if(Mp[T[i]]==){
continue;
}else{
Str[Mp[T[i]]-]=T[i];
}
}
//cout<<Str<<endl;
for(int i=;i<max(lent,lens);i++){
for(int j=;j<mp[Str[i]];j++){
Ctr+=Str[i];
}
}
for(int i=;i<lent;i++){
if(Mp[T[i]]==){
Ctr+=T[i];
}
}
return Ctr;
}
};

73th LeetCode Weekly Contest Custom Sort String的更多相关文章

  1. 【LeetCode】791. Custom Sort String 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 按顺序构造字符串 排序 日期 题目地址:https: ...

  2. 73th LeetCode Weekly Contest Rotated Digits

    X is a good number if after rotating each digit individually by 180 degrees, we get a valid number t ...

  3. 73th LeetCode Weekly Contest Domino and Tromino Tiling

    We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may ...

  4. 73th LeetCode Weekly Contest Escape The Ghosts

    You are playing a simplified Pacman game. You start at the point (0, 0), and your destination is(tar ...

  5. 791. Custom Sort String - LeetCode

    Question 791. Custom Sort String Solution 题目大意:给你字符的顺序,让你排序另一个字符串. 思路: 输入参数如下: S = "cba" T ...

  6. LeetCode Weekly Contest 8

    LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...

  7. leetcode weekly contest 43

    leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...

  8. LeetCode Weekly Contest 23

    LeetCode Weekly Contest 23 1. Reverse String II Given a string and an integer k, you need to reverse ...

  9. LeetCode Weekly Contest

    链接:https://leetcode.com/contest/leetcode-weekly-contest-33/ A.Longest Harmonious Subsequence 思路:hash ...

随机推荐

  1. 多版本Python共存时pip给指定版本的python安装package的方法

    在Linux安装了多版本Python时(例如python2.7和3.6),pip安装的包不一定是用户想要的位置,此时可以用 -t 选项来指定位置. 例如目标位置是/usr/local/lib/pyth ...

  2. Mathf.Sin正弦

    输入参数是弧度 Mathf.Sin   public static float Sin(float f); Parameters Description Returns the sine of ang ...

  3. 使用 Anthem.NET 的经验小结

    1. 不依靠 Panel 来做省事的区域性 Ajax. 2. 控件不要图偷懒设置 AutoUpdateAfterCallBack = true. 而是每次需要更新的时候指定 UpdateAfterCa ...

  4. Oracle 12c 多租户在 CDB 中 Plug A PDB,Unplugging A PDB

    Oracle 数据库 12 c 中介绍了多租户选项允许单个容器数据库 (CDB) 来承载多个单独的可插拔数据库 (PDB).本文简单的演示了如何在 CDB 中 Plug A PDB,Unpluggin ...

  5. asp.net定时任务

    我们这边使用的定时任务框架是Quartz.Net,可以实现异常灵活的定时任务,开发人员只要编写少量的代码就可以实现“每隔一小时执行”.每天22点执行,每月18日下午执行等等各种定时任务. Quartz ...

  6. POJ2528(离散化+线段树区间更新)

     Mayor's posters Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u De ...

  7. java代码for循环+缓冲流类

    总结:这个结果竟然是对的.我错了. package com.da; //创建一个String对象的数组,然后执行读取文本,把文本每一行存入数组,它将读取到100行 //或直接到你按”stop“才停止, ...

  8. SpringMvc之参数绑定注解详解之一

    引言: 前段时间项目中用到了REST风格来开发程序,但是当用POST.PUT模式提交数据时,发现服务器端接受不到提交的数据(服务器端参数绑定没有加 任何注解),查看了提交方式为application/ ...

  9. WPF Canvas

    Canvas为容器控件,用于定位. 1.基本应用 <Border HorizontalAlignment="Left" VerticalAlignment="Top ...

  10. javadoc 工具生成开发API文档

    =====================先来一点成就感===================== package com.springMybatis.dao; import com.springMy ...