题目传送门

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的更多相关文章

  1. 【题解】【字符串】【BFS】【Leetcode】Word Ladder

    Given two words (start and end), and a dictionary, find the length of shortest transformation sequen ...

  2. 126. Word Ladder II

    题目: Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transfo ...

  3. [Leetcode Week5]Word Ladder II

    Word Ladder II 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/word-ladder-ii/description/ Descripti ...

  4. [Leetcode Week5]Word Ladder

    Word Ladder题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/word-ladder/description/ Description Give ...

  5. 【leetcode刷题笔记】Word Ladder II

    Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...

  6. [LeetCode] Word Ladder 词语阶梯

    Given two words (beginWord and endWord), and a dictionary, find the length of shortest transformatio ...

  7. [LeetCode] Word Ladder II 词语阶梯之二

    Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...

  8. LeetCode:Word Ladder I II

    其他LeetCode题目欢迎访问:LeetCode结题报告索引 LeetCode:Word Ladder Given two words (start and end), and a dictiona ...

  9. 【leetcode】Word Ladder

    Word Ladder Total Accepted: 24823 Total Submissions: 135014My Submissions Given two words (start and ...

  10. 【leetcode】Word Ladder II

      Word Ladder II Given two words (start and end), and a dictionary, find all shortest transformation ...

随机推荐

  1. 【转载】 Pytorch手动释放显存

    原文地址: http://www.shijinglei.com/2020/04/20/pytorch%E9%87%8A%E6%94%BE%E6%98%BE%E5%AD%98/ ============ ...

  2. Linux统计文件目录下文件的数目命令

    Linux下有三个命令:ls.grep.wc.通过这三个命令的组合可以统计目录下文件及文件夹的个数. 1.ls -l | grep "^-" | wc -l:统计当前目录下文件的个 ...

  3. 09-canvas绘制坐标系

    1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="U ...

  4. disconf分布式配置管理(一) 安装与配置

    一.背景 在生产部署过程中,遇到以下问题: 1.由于节点较多,每次增量修改配置文件后都需要每个节点替换配置文件. 2.有些动态配置修改后,需要重启服务. 二.解决方案 1.使用linux文件共享配置文 ...

  5. 2023 ICPC 合肥游记

    board zsy 11.24 开始嗓子疼了,但可以忍受.晚上睡的很不舒服 11.25 起床就开始难受,还得骑车到地铁站,应该打个车来着.不过路上拍到了很好看的朝霞(写到这里才想起来还没发朋友圈给 t ...

  6. Atcoder ABC299 E-G

    Atcoder ABC299 E-G E - Nearest Black Vertex 链接: E - Nearest Black Vertex (atcoder.jp) 简要题意: 问题陈述 给你一 ...

  7. 禅道项目管理系统权限绕过漏洞(QVD-2024-15263)

    本文所涉及的任何技术.信息或工具,仅供学习和参考之用,请勿将文章内的相关技术用于非法目的,如有相关非法行为与文章作者无关.请遵守<中华人民共和国网络安全法>. 1. 概述 1.1 基本信息 ...

  8. Win32 ListCtrl控件点击列标题排序

    1.在WM_NOTIFY消息中捕获鼠标点点击列的索引 int MyMainDialog::OnNotify(NMHDR* pNMhdr) { if (pNMhdr->idFrom == IDC_ ...

  9. 走进Docker的世界--(库存学习笔记)

    第一天 走进Docker的世界 介绍docker的前世今生,了解docker的实现原理,以Django项目为例,带大家如何编写最佳的Dockerfile构建镜像.通过本章的学习,大家会知道docker ...

  10. Ollama + JuiceFS:一次拉取,到处运行

    今天这篇博客转载自我们的全栈工程师朱唯唯.在使用 Ollma 进行大模型加载时,她尝试使用了 JuiceFS 进行模型共享,JuiceFS 的数据预热和分布式缓存功能显著提升了加载效率,优化了性能瓶颈 ...