题解: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 ...
随机推荐
- 为wsl ubuntu设置固定IP
参考: https://www.cnblogs.com/lidabo/p/16855858.html https://zhuanlan.zhihu.com/p/515068209 ========== ...
- 38k Star!颠覆传统BI,Metabase新一代智能数据分析工具
Metabase 是一个开源的商业智能(BI)工具,帮助用户轻松地从数据库中提取数据,并将其转化为易于理解的图表和仪表板.与传统的 BI 工具相比,Metabase 不需要用户具备编写 SQL 的能力 ...
- Flex相册
有一个项目用到了Flex,于是抽时间用flex与java做了一个相册,并且添加了上传功能,不过暂时没有针对具体的用户进行存储.下面是图片:
- Go 监控告警入门 Opentelemetry
前言 Opentelemetry 分布式链路跟踪( Distributed Tracing )的概念最早是由 Google 提出来的,发展至今技术已经比较成熟,也是有一些协议标准可以参考.目前在 Tr ...
- Win32 sdk 下树形控件响应鼠标单击与双击,获得选中项的名称
//窗口过程函数INT_PTR CALLBACK myWin::myWinDlgProc(HWND dlgHwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ...
- c++学习笔记(二):引用
c++中的引用 引用变量是一个别名,也就是说,它是某个已存在变量的另一个名字.一旦把引用初始化为某个变量,就可以使用该引用名称或变量名称来指向变量. C++ 引用 vs 指针 引用很容易与指针混淆,它 ...
- Word在不同电脑排版异常
Word在不同电脑排版异常 问题描述 今天又有同学向我抱怨用 word 写的论文明明在自己的电脑格式调的好好的,怎么在导师那格式又乱了,害的挨批. 笔者也遇到过该问题,正好趁这次机会简单整理一下. 注 ...
- springboot 集成 onlyoffice 实现文档预览、编辑、pdf转化、缩略图生成
开源地址 https://gitee.com/lboot/lucy-onlyoffice 介绍 lucy-onlyoffice是依赖于onlyoffice的springboot文档预览编辑集成解决方案 ...
- ES6之常用开发知识点:let 和 const 命令详解(二)
let命令 基本用法 { let a = 10; var b = 1; } a // ReferenceError: a is not defined. b // 1 根据上面结果显示,let声明的变 ...
- ASP.NET Core – TagHelper
前言 以前写的 Asp.net core 学习笔记之 Tag Helper, 这篇是整理版. 参考 Docs – Author Tag Helpers in ASP.NET Core Creating ...