hiho一下 第230周 Smallest Substring
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
vector<int>G[27];
int vis[27];
int k;
char s[100010];
char str[100010];
int main()
{
cin>>k;
cin>>s;
int n=strlen(s);
for(int i=0;i<27;i++)
G[i].clear();
for(int i=0;i<n;i++)
{
int u=s[i]-96;
G[u].push_back(i);
}
memset(vis, 0, sizeof(vis));
int pos=-1;
for(int i=0;i<k;i++)
{
bool flag=false;
for(int j=1;j<27;j++)
{
int u=vis[j];
if(u>=G[j].size())
continue;
for(int y=u;y<G[j].size();y++)
{
int x=G[j][y];
if(n-1-x>=k-i-1&&x>pos)
{
str[i]=s[x];
pos=x;
vis[j]=y+1;
flag=true;
break;
}
}
if(flag)
break;
}
}
str[k]='\0';
cout<<str<<endl;
return 0;
}
相關文章
- hiho一下 第229周:Same Letters In A Row
- [LeetCode] K-th Smallest Prime Fraction 第K小的質分數LeetCodeFraction質分數
- Js的substring和C#的SubstringJSC#
- JavaScript substring()JavaScript
- [LeetCode] 910. Smallest Range IILeetCode
- LeetCode之Smallest Range I(Kotlin)LeetCodeKotlin
- 【Leetcode】1081. Smallest Subsequence of Distinct CharactersLeetCode
- [LeetCode] 230. Kth Smallest Element in a BSTLeetCode
- Smallest Range I 最小差值 I
- C# SubstringC#
- [LeetCode] 378. Kth Smallest Element in a Sorted MatrixLeetCode
- C#中substringC#
- Substring with Concatenation of All Words
- SQL Server SUBSTRING FunctionsSQLServerFunction
- MySQl 擷取函式 left(),right(),substring(),substring_index() 的用法MySql函式Index
- ABC347B Substring
- String 類的 substring () 方法
- LeetCode 5 (Longest Palindromic Substring)LeetCode
- substr()和substring()區別
- SUBSTRING() 與 CONV() 函式函式
- 第134期 勘誤且自嘲一下(20240115)
- LeetCode 1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance??LeetCode
- D. Non-Palindromic Substring
- Leetcode 30 Substring with Concatenation of All WordsLeetCode
- mysql 函式substring_index()MySql函式Index
- 【mysql】SUBSTRING_INDEX 用法舉例MySqlIndex
- CF163A Substring and Subsequence 題解
- Java基礎系列-substring的原理Java
- Leetcode 3 Longest Substring Without Repeating CharactersLeetCode
- #3 Longest Substring Without Repeating Characters[M]
- 【PAT甲級A1038】Recover the Smallest Number (30分)(c++)C++
- [LeetCode] 3090. Maximum Length Substring With Two OccurrencesLeetCode
- [LeetCode] 2414. Length of the Longest Alphabetical Continuous SubstringLeetCodeAlphabet
- Solution - Atcoder ABC280Ex Substring Sort
- CF1234F Yet Another Substring Reverse
- Leetcode 3. Longest Substring Without Repeating CharactersLeetCode
- Swift 中的 String 和 Substring 如何工作Swift
- JavaScript 中substr與 substring 的區別JavaScript