题解:AT_abc370_c [ABC370C] Word Ladder
题目传送门
luogu观看
简要题意
给两个序列 \(S\) 和 \(T\),输出的第一个数是它能改变的总个数,后面跟着的第 \(i\) 个是改变 \(i\) 个数之后,字典序最小的结果。
思路
当 \(S\) 与 \(T\) 相等的话,那就无法改变了,直接输出 \(0\)。
对于总数只要 \(T_i \ne S_i\) 那它就可以改,所以只要 \(T_i \ne S_i\) 答案就加一。
- 要让字典序最小,那我们从前面开始枚举,只要 \(T_i < S_i\) 就替换,然后输出。
- 否则如果 \(T_i > S_i\) 记录位置。等枚举完后,从后往前把记录的位置也换了。
代码
#include<bits/stdc++.h>
using namespace std;
char s[1000],t[1000],ss[1000];
int n,qw,h[100000000];
main()
{
ios::sync_with_stdio(false);
cin.tie(),cout.tie();
cin>>s>>t;
if(s==t)
{
cout<<0;
return 0;
}
n=qw=strlen(s);
for(int i=0;i<n;i++)
ss[i]=s[i];
int qq=0;
for(int i=0;i<n;i++)
{
if(s[i]==t[i])
continue;
qq++;
}
cout<<qq<<endl;
qq=0;
for(int i=0;i<n;i++)
{
if(s[i]==t[i])
continue;
if(s[i]<t[i])
{
h[++qq]=i;
continue;
}
s[i]=t[i];
cout<<s<<endl;
}
for(int i=qq;i>=1;i--)
{
int j=h[i];
s[j]=t[j];
cout<<s<<endl;
}
}
题解:AT_abc370_c [ABC370C] Word Ladder的更多相关文章
- 【题解】【字符串】【BFS】【Leetcode】Word Ladder
Given two words (start and end), and a dictionary, find the length of shortest transformation sequen ...
- 126. Word Ladder II
题目: Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transfo ...
- [Leetcode Week5]Word Ladder II
Word Ladder II 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/word-ladder-ii/description/ Descripti ...
- [Leetcode Week5]Word Ladder
Word Ladder题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/word-ladder/description/ Description Give ...
- 【leetcode刷题笔记】Word Ladder II
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...
- [LeetCode] Word Ladder 词语阶梯
Given two words (beginWord and endWord), and a dictionary, find the length of shortest transformatio ...
- [LeetCode] Word Ladder II 词语阶梯之二
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...
- LeetCode:Word Ladder I II
其他LeetCode题目欢迎访问:LeetCode结题报告索引 LeetCode:Word Ladder Given two words (start and end), and a dictiona ...
- 【leetcode】Word Ladder
Word Ladder Total Accepted: 24823 Total Submissions: 135014My Submissions Given two words (start and ...
- 【leetcode】Word Ladder II
Word Ladder II Given two words (start and end), and a dictionary, find all shortest transformation ...
随机推荐
- 【转载】 arXiv论文提交流程
原文地址: https://blog.csdn.net/u010705932/article/details/105834469 =================================== ...
- 【模板】树的直径(dfs & dp)
树的直径 给定n个点 n-1条边 和每条边的val 输出直径的大小和 直径上的点的序号 input: 8 1 2 2 1 3 1 1 5 10 2 4 3 4 6 4 3 7 5 7 8 2 outp ...
- 安装RabbitMQ遇到的一些坑
Ubantu18.0正确安装RabbitMQ 1.安装erlang 因为RabbitMQ需要erlang语言的支持,所以我们需要先安装erlang. sudo apt-get install erla ...
- avdmanager 返回了非零退出代码: 1。
最近做了一次系统还原,很多功能都出现了异常 重装了 Visual Studio 之后创建安卓仿真器的时候遇到问题,说"avdmanager 返回了非零退出代码: 1." 解决思路 ...
- 是技术牛人,如何拿到国内IT巨头的Offer
不久前,byvoid面阿里星计划的面试结果截图泄漏,引起无数IT屌丝的羡慕敬仰.看看这些牛人,NOI金牌,开源社区名人,三年级开始写Basic...在跪拜之余我们不禁要想,和这些牛人比,作为绝大部分技 ...
- [Linux]yum下载慢!!
有全局代理,但是yum下载特别慢,怎么办? 确保/etc/yum.conf文件中代理配置的语法正确,包括代理服务器的地址和端口号,如下所示: proxy=http://your_proxy_serve ...
- vue 中 elementUI el-table 实现滚动加载
vue 中 elementUI el-table 实现滚动加载 一.需求 vue 中 elementUI el-table 实现滚动加载,场景:当表格需要显示大量数据时,又想通过一页来进行展示数据. ...
- 戴尔笔记本游匣DELL G16 7620更换固态硬盘从选购固态硬盘到系统和应用程序迁移(克隆)全过程(教程)
又到了捣鼓电脑的时候了.去年(2022年)8月14日买的电脑,当时7月份刚出戴尔游匣G16,搜了一下,2022年7月22日,戴尔首发游匣G16国行版本. 到现在也就用了差不多半年的时间,我的内存满了, ...
- EntityFramework Core并发迁移解决方案
场景 目前一个项目中数据持久化采用EF Core + MySQL,使用CodeFirst模式开发,并且对数据进行了分库,按照目前颗粒度分完之后,大概有一两百个库,每个库的数据都是相互隔离的. 借鉴了G ...
- socket close和shutdown的区别,TIME_WAIT和CLOSE_WAIT
TCP主动关闭连接 appl: close(), --> FIN FIN_WAIT_1 //主动关闭socket方,调用close关闭socket,发FIN < ...