题解: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 ...
随机推荐
- IPython notebook(Jupyter notebook)指定IP和端口运行
1. 使用conda 安装 jupyter conda install jupyter 2. 在服务器端不打开浏览器,指定 端口, IP , 运行jupyter notebook 这里假设端口 ...
- 如何在多台Linux系统主机上实现ssh免密访问——成公钥文件id_rsa.pub(数字签名RSA)
假设共有三台Linux主机,为matser,slave1,slave2,现在要实现master主机可以ssh免密访问master主机自身以及slave1.slave2. 原理: 主机调用秘钥生成命令, ...
- 【转载】 在Ubuntu环境下,搜狗输入法乱码问题的解决
原文作者:高坦的博客 | Tan's Blog 原文链接:https://www.cnblogs.com/gtscool/p/12234104.html本文采用 BY-NC-SA 许可协议.转载请注明 ...
- .NET电子邮件高效处理解决方案
前言 在日常软件开发中,电子邮件处理是一个不可或缺的功能,无论是用户注册验证.通知推送还是日常的业务沟通,都离不开电子邮件的支持.今天大姚给大家分享2款.NET开源.高效.强大的.NET电子邮件处理库 ...
- JAVA学习——JDK开发环境配置
2024/07/08 一.JDK下载 二.安装与JDK开发环境配置(Windows) 三.安装与JDK开发环境配置(Linux) 一.JDK下载与安装 网址: https://www.oracle.c ...
- MATLAB 绘制 K 线图
需要安装 Financial Toolbox. % 示例数据 openPrices = [100, 102, 104, 103, 105]; highPrices = [105, 107, 106, ...
- P 问题和 NP 问题的简单理解
P/NP问题 | 维基百科 P 问题 P 问题的定义是:所有可以由一个确定型图灵机在多项式表达的时间内解决的问题 P 代表 Polynomial-time (adj. 多项式时间) 简单理解:答案可以 ...
- Ubuntu 切换显示管理器
比较流行的显示管理器有: gdm3 - GNOME Display Manager lightdm - Light Display Manager sddm - Simple Desktop Disp ...
- Web刷题之polarctf靶场(1)
PolarCTF 1.XFF 打开靶场发现需要ip为1.1.1.1的用户才行, 打开BurpSuite进行抓包并对数据包进行修改,根据题目XFF提示 flag{847ac5dd4057b1ece411 ...
- 在虚拟机CentOS中安装jdk
公众号本文地址:在虚拟机CentOS中安装jdk 本文主要是记录在CentOS中安装新的JDK的过程. 在虚拟机的centos中安装Jdk主要分为三步,第一步上传jdk文件到centos中,第二步解压 ...