codeforce A. Many Equal Substrings
http://codeforces.com/contest/1029/problem/A
嗳,简单的题做起来是真的舒服qwq
1 public static void main(String[] args) {
2 Scanner io=new Scanner(System.in);
3 int n=io.nextInt(),k=io.nextInt();
4 String str=io.nextLine();
5 while (str.length()==0)str=io.nextLine();
6
7 String ans="";
8 for (int len=str.length()-1;len>=0;len--){
9 if (len==0){
10 for (int i = 0; i < k; i++) ans+=str;
11 System.out.println(ans);
12 return;
13 }
14 String s1=str.substring(0,len);
15 String s2=str.substring(str.length()-len);
16 if (s1.equals(s2)){
17 ans+=str;
18 s1=str.substring(len);
19 for (int i = 0; i < k - 1; i++) ans+=s1;
20 System.out.println(ans);
21 return;
22 }
23 }
24 }
codeforce A. Many Equal Substrings的更多相关文章
- CodeForces A. Many Equal Substrings
http://codeforces.com/contest/1029/problem/A You are given a string tt consisting of nn lowercase La ...
- 【leetcode】1208. Get Equal Substrings Within Budget
题目如下: You are given two strings s and t of the same length. You want to change s to t. Changing the ...
- CF1029A Many Equal Substrings
题目描述 你有一个字符串t,它由n个字母组成. 定义一个字符串s的子串为s[l...r],表示从位置l到r构成的一个新的串. 你的目标是构造一个字符串s,使得它的可能长度最小,要求s中存在k个位置i, ...
- A. Many Equal Substrings(水题)
思路: 直接比较橘色框里的取第一次相等,即可. #include<iostream> #include<string> using namespace std; string ...
- 【CF1029A】Many Equal Substrings(模拟)
题意:给定一个长度为n的串s,要求构造一个长度最小的使s出现了k次的串,可以重叠 n<=50,k<=50 思路:计算一下前后缀相同长度 #include<cstdio> #in ...
- Many Equal Substrings CodeForces - 1029A (kmp next数组应用)
题目大意 题目看样例也能猜到就是输出最短的循环串. 吐槽 明明是div3第一题为啥子还会用到kmp的知识? 解法 这个题仔细看发现是求最长可去除的后缀,也就是说去除跟下一个相同的字符串还能连接起来.这 ...
- 【LeetCode】1208. 尽可能使字符串相等 Get Equal Substrings Within Budget (Python)
作者: 负雪明烛 id: fuxuemingzhu 公众号:每日算法题 本文关键词:LeetCode,力扣,算法,算法题,字符串,并查集,刷题群 目录 题目描述 示例 解题思路 滑动窗口 代码 刷题心 ...
- Codeforces Round #352 (Div. 2) B - Different is Good
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to b ...
- [Swift]LeetCode828. 独特字符串 | Unique Letter String
A character is unique in string S if it occurs exactly once in it. For example, in string S = " ...
- Unique Letter String LT828
A character is unique in string S if it occurs exactly once in it. For example, in string S = " ...
随机推荐
- Potree 002 Desktop开发环境搭建
1.工程创建 我们使用Visual Studio 2022开发,把下载好后的PotreeDesktop源码添加到Visual Studio中. 打开Visual Studio 2022,新建Asp.N ...
- [C++]我的理解之内存对齐
问题1:为什么要内存对齐? 平台原因:不是所有的平台都能访问到任意地址上的任何数据,如果在特定的地址上找不到数据的话就会抛出硬件异常. 性能问题:简单的来说如果没有使用内存对齐的话,相对于内存对齐,C ...
- 普冉PY32系列(一) PY32F0系列32位Cortex M0+ MCU简介
目录 普冉PY32系列(一) PY32F0系列32位Cortex M0+ MCU简介 普冉PY32系列(二) Ubuntu GCC Toolchain和VSCode开发环境 PY32F0系列上市其实相 ...
- 【Allwinner】---全志GPIO号 计算
全志的GPIO号在 sunxi-gpio.h 中定义 sunxi-gpio.h1二.GPIO号定义#define SUNXI_PA_BASE 0#define SUNXI_PB_BASE 32#def ...
- 异步async await 相关知识点总结以及代码练习
<script> const setTimeoutToPromise = duration => new Promise(resolve => { setTimeout(res ...
- 函数式编程思想概述-冗余的Runnable代码
函数式编程思想概述 在数学中,函数就是有输入量.输出星的一套计算方案,也就是"拿什么东西做什么事情".相对而言,面向对象过分强调"必须通过对象的形式来做事情", ...
- Python 异步集群使用
目前在做Python项目用到同步和异步的方法使用Redis单机,现在要增加兼容Redis集群.也就说当前项目用到中以下4种Python使用Redis的方法都用到了. - 同步 异步 单机 涉及 涉及 ...
- AI 制作 3D 素材|基于 AI 5 天创建一个农场游戏,第 3 天
欢迎使用 AI 进行游戏开发! 在本系列中,我们将使用 AI 工具在 5 天内创建一个功能完备的农场游戏.到本系列结束时,您将了解到如何将多种 AI 工具整合到游戏开发流程中.本文将向您展示如何将 A ...
- 安装KaLi操作系统并优化
安装KaLi操作系统并优化 1. 开启ROOT登录 安装操作系统跳过,下面直接做系统优化,方便以后使用! 有两种方法,可以实现开机以root身份登录kali系统. 第一种方法如下: 在终端下输入所需命 ...
- Solon2 之基础:一、常用应用配置说明
约定参考: //资源路径约定(不用配置:也不能配置) resources/app.yml( 或 app.properties ) #为应用配置文件 resources/WEB-INF/static/ ...