CSL 的字符串(stack)

链接:https://ac.nowcoder.com/acm/contest/551/D
来源:牛客网
 

CSL 以前不会字符串算法,经过一年的训练,他还是不会……于是他打算向你求助。
 

给定一个字符串,只含有可打印字符,通过删除若干字符得到新字符串,新字符串必须满足两个条件:

  • 原字符串中出现的字符,新字符串也必须包含。
  • 新字符串中所有的字符均不相同。
  • 新字符串的字典序是满足上面两个条件的最小的字符串。

 

输入描述:

 

仅一行,有一个只含有可打印字符的字符串 s。

 

|s|≤105|s|≤105

输出描述:

在一行输出字典序最小的新字符串。

示例1

输入

复制

bab

输出

复制

ab

示例2

输入

复制

baca

输出

复制

bac

备注:

ASCII字符集包含 94 个可打印字符(0x21 - 0x7E),不包含空格。

先放出代码:

#include<iostream>
using namespace std;
#include<bits/stdc++.h>
const int maxn=100005;
typedef long long ll;
int vis[maxn];
int used[maxn];

int main()
{
	string s;
	cin>>s;
	stack<char>v;
	
	for(int i=0;i<s.length();i++)
	{
		used[ s[i] ]++;
	}
	 
	vis[ s[0] ]=1;  
	used[ s[0] ]--;
	v.push(s[0]);
	
	for(int i=1;i<s.length();i++)
	{
		used[ s[i] ]--;
		
		if(vis[s[i]]==0)
		{
				while(!v.empty()&&v.top()>s[i]&&used[ v.top() ])
				{
					char c=v.top();
					vis[c]=0;
					v.pop();
				}
				
				v.push( s[i] );
				vis[s[i]]=1;
		}
	}
	
	string ans;
	while(!v.empty())
	{
		ans+=v.top();
		v.pop();
	}
	
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
	
	return 0;
}


一开始不知道怎么来模拟这个字符串,需要将多个字符化为删除 成为一个,并且使最后的字典序最小,一开始并不知道怎么来模拟。最后看了大神的代码。思路是 先是将各种字符计数 ,然后用单调有序栈来存字符,字典序最小。1.如果当前栈顶的元素比要加进来的元素字典序小(假定这个栈顶字符出现数大于2,是要删除的字符),我们就不能把这个删除,那么后面的再出现这个字符,我们就得将这个删除掉;2.如果栈顶元素比要加进来的字符字典序大,我们就要将目前栈顶元素pop 掉,使字典序小一些。这样的话,我们在以后继续遇见这个字符,我们还需要 加进来(一种字符只能留一个,不能多,也不能少)。 上面的这两个情况操作我们需要一个标记数组来进行标记,看看是 第几种情况 1 还是 2,我们都需要进行标记,判断如果是第一种情况,我们后面再遇见这个字符,我们这个标记数组就可以 派上用场,就不会存进 stack 中相同的字符了。 

ERROR: device-tree-xilinx-v2020.2+gitAUTOINC+f725aaecff-r0 do_compile: Error executing a python function in exec_python_func() autogenerated: The stack trace of python calls that resulted in this exception/failure was: File: 'exec_python_func() autogenerated', lineno: 2, function: <module> 0001: *** 0002:devicetree_do_compile(d) 0003: File: '/home/ljj/petalinux/csl_zynqsys_1/components/yocto/layers/core/meta/classes/devicetree.bbclass', lineno: 131, function: devicetree_do_compile 0127: if not(os.path.isfile(dtspath)) or not(dts.endswith(".dts") or devicetree_source_is_overlay(dtspath)): 0128: continue # skip non-.dts files and non-overlay files 0129: except: 0130: continue # skip if can't determine if overlay *** 0131: devicetree_compile(dtspath, includes, d) 0132:} 0133: 0134:devicetree_do_install() { 0135: for DTB_FILE in `ls *.dtb *.dtbo`; do File: '/home/ljj/petalinux/csl_zynqsys_1/components/yocto/layers/core/meta/classes/devicetree.bbclass', lineno: 119, function: devicetree_compile 0115: dtcargs += ["-i", i] 0116: dtcargs += ["-o", "{0}.{1}".format(dtname, "dtbo" if isoverlay else "dtb")] 0117: dtcargs += ["-I", "dts", "-O", "dtb", "{0}.pp".format(dts)] 0118: bb.note("Running {0}".format(" ".join(dtcargs))) *** 0119: subprocess.run(dtcargs, check = True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 0120: 0121:python devicetree_do_compile() { 0122: includes = expand_includes("DT_INCLUDE", d) 0123: listpath = d.getVar("DT_FILES_PATH") File: '/opt/pkg/petalinux/2020.2/components/yocto/buildtools/sysroots/x86_64-petalinux-linux/usr/lib/python3.7/subprocess.py', lineno: 512, function: run 0508: raise 0509: retcode = process.poll() 0510: if check and retcode: 0511: raise CalledProcessError(retcode, process.args, *** 0512: output=stdout, stderr=stderr) 0513: return CompletedProcess(process.args, retcode, stdout, stderr) 0514: 0515: 0516:def list2cmdline(seq): Exception: subprocess.CalledProcessError: Command '['dtc', '-@', '-p', '0x1000', '-i', '/home/ljj/petalinux/csl_zynqsys_1/project-spec/configs/../../components/plnx_workspace/device-tree/device-tree', '-i', '/home/ljj/petalinux/csl_zynqsys_1/build/tmp/work-shared/zynq-generic/kernel-source/scripts/dtc/include-prefixes', '-i', '/home/ljj/petalinux/csl_zynqsys_1/build/tmp/work/zynq_generic-xilinx-linux-gnueabi/device-tree/xilinx-v2020.2+gitAUTOINC+f725aaecff-r0', '-i', '/home/ljj/petalinux/csl_zynqsys_1/build/tmp/work-shared/zynq-generic/kernel-source/arch/arm/boot/dts', '-o', 'system-top.dtb', '-I', 'dts', '-O', 'dtb', 'system-top.dts.pp']' returned non-zero exit status 1. Subprocess output: Error: /home/ljj/petalinux/csl_zynqsys_1/build/tmp/work/zynq_generic-xilinx-linux-gnueabi/device-tree/xilinx-v2020.2+gitAUTOINC+f725aaecff-r0/system-user.dtsi:15.1-6 syntax error FATAL ERROR: Unable to parse input tree ERROR: Logfile of failure stored in: /home/ljj/petalinux/csl_zynqsys_1/build/tmp/work/zynq_generic-xilinx-linux-gnueabi/device-tree/xilinx-v2020.2+gitAUTOINC+f725aaecff-r0/temp/log.do_compile.22923 ERROR: Task (/home/ljj/petalinux/csl_zynqsys_1/components/yocto/layers/meta-xilinx/meta-xilinx-bsp/recipes-bsp/device-tree/device-tree.bb:do_compile) failed with exit code '1' NOTE: Tasks Summary: Attempted 4295 tasks of which 359 didn't need to be rerun and 1 failed. Summary: 1 task failed: /home/ljj/petalinux/csl_zynqsys_1/components/yocto/layers/meta-xilinx/meta-xilinx-bsp/recipes-bsp/device-tree/device-tree.bb:do_compile Summary: There was 1 ERROR message shown, returning a non-zero exit code. ERROR: Failed to build project 结合上面设备树文件的代码,分析一下为什么会报错
最新发布
03-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值