You're Given a String... CodeForces - 23A

初识数据结构之入门必懂——线性表(顺序表) 本文将介绍数据结构中的线性表与线性表中最简单的结构——顺序表 阅读详情

You're Given a String...

CodeForces - 23A

You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).

Input

The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100.

Output

Output one number — length of the longest substring that can be met in the string at least twice.

Example
Input
abcd
Output
0
Input
ababa
Output
3
Input
zzz
Output
2
一道水题,让我wa了五遍才过,脑子思路不清楚,直接暴力,四个循环嵌套,最外面两个选择子串,里面两个从头开始一个一个对比子串 code:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int main(){
    string s;
    cin >> s;
    int i,j,k;
    int longest = 0;
    for(i = 0; i < s.length(); i++){
        for(j = i; j < s.length(); j++){//选择出子串i到j
            int index = i;
            int cnt = 0;
            for(k = 0; k < s.length(); k++){//从头比较
                int q = 0;
                int flag = 1;
                while(q < (j-i+1)){//从k起点,然后往后长度为j-i+1,比较已经选出的子串,比较完后起始点挪到下一个
                    if(s[i+q] != s[k+q]){
                        flag = 0;
                        break;
                    }
                    else
                        q++;
                }
                if(flag)
                    cnt++;
            }
            if(cnt >= 2){
                longest = max(longest,j-i+1);
            }
        }
    }
    cout << longest << endl;
    return 0;
}


C++五子棋人机对战 使用C++,开发五子棋人机对战,快速提升C++项目开发能力。 阅读详情

相关推荐

扣子(coze)案例^第22期:零代码打造小红书竞品监控系统+AI自动生成运营策略建议

本文详细介绍了如何利用扣子(coze)平台零代码搭建小红书竞品监控系统。该系统通过自动化工作流抓取竞品笔记数据,并存入飞书多维表格,结合AI能力自动生成包含可视化分析报告在内的运营策略建议,帮助运营者高效进行数据驱动的市场分析。

weixin_29313239的博客 1002

You're Given a String...

1、点击打开链接 2、题目大意:给定一个字符串,求重复出现的子串的最大长度 题目很简单,但是错了好几次,最后才发现数组开小了 3、题目: A. You're Given a String... time limit per test 2 seconds memory limit per test 256 megabytes input standard

sdjzping的专栏 904

深入解析DDR5 RFM机制:从JESD79-5标准到硬件实现

本文深入解析了DDR5内存标准中的关键机制——RFM(Refresh Management)。文章从JESD79-5标准出发,详细阐述了RFM如何通过RAA计数器实现从被动定时到主动响应的智能刷新管理,并探讨了其硬件实现细节、命令调度挑战及系统级设计考量,为芯片设计工程师优化DDR5内存子系统性能与可靠性提供了实践指导。

fff88的博客 486

CodeForces - 1038A Equality 水题

You are given a string ss of length nn, which consists only of the first kk letters of the Latin alphabet. All letters in string ss are uppercase. A subsequence of string ss is a string that can be d...

祈的博客 830

完整指南:从基础到高级使用 Semantic Kernel

通过本文的学习,你已经掌握了从基础到高级的使用方法。安装并配置。使用简单的文本生成和自然语言处理任务。利用任务链和工具扩展构建复杂的工作流。通过记忆管理上下文,创建更智能的应用。扩展多模态处理能力,集成图像和音频分析。将应用部署到云端,并通过 Azure Functions 提供智能服务。无论是构建简单的对话应用,还是创建多模态智能服务,都提供了强大的工具和灵活的扩展机制。希望这篇文章能帮助你更好地理解并运用这个框架,构建出更加智能和高效的应用。

net core ,前端 ,python 全栈开发 2805

基于555定时器的D类功放设计:从PWM原理到无反馈电路实践

D类功放(数字功放)是一种高效率的音频放大技术,其核心原理是脉冲宽度调制(PWM)。它将输入的模拟音频信号转换为一系列高速开关的脉冲,通过控制功率开关管(如MOSFET)的通断,再经低通滤波器还原放大后的音频。相比传统AB类功放,其转换效率通常超过90%,显著降低了热能损耗。这项技术在追求高能效和小型化的现代音频设备中价值凸显,广泛应用于有源音箱、汽车音响和便携式设备。本文聚焦于一种独特的实现方案:以经典的555定时器芯片为核心,构建一个无整体负反馈的D类功放。通过剖析其PWM调制器、FET电压-电流转换级

weixin_30162121的博客 220

【CodeForces - 1038A 】Equality (思维水题,预处理字符串)

题干: You are given a string ss of length nn, which consists only of the first kk letters of the Latin alphabet. All letters in string ss are uppercase. A subsequence of string ss is a string that can...

xuanweiace的博客 823

飞书组织架构同步至LDAP:实现企业应用统一身份认证的实战指南

本文详细介绍了如何将飞书组织架构同步至LDAP,实现企业应用统一身份认证的实战方案。通过飞书开放平台API与LDAP服务的集成,企业可以大幅减少账号管理工作量,提升IT效率。文章涵盖技术架构设计、密码策略、详细配置步骤及自动化同步实现,特别适合需要统一认证体系的中大型企业。

weixin_29172201的博客 330

A. You're Given a String...

A. You're Given a String... time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You're given a string of lower-case Latin

sdjzqing的专栏 898

CUDA编程00 - 配置CUDA开发环境

第一步:在一台装有Nvidia显卡和驱动的机器上,用nvidia-smi命令查看显卡所支持cuda版本。安装时按提示下一步即可,安装完成用 nvcc -V 命令检查是否成功。第二步: 到Nvidia官网下载CUDA Toolkit并安装,第三步:编写HelloWorld。

GPU全栈博主 1359

YOLOv5 实现 10 种热力图可视化方式教程 | GradCAM XGradCAM ScoreCAM LayerCAM HiResCAM EigenCAM....

基于梯度计算类激活图,是最经典的热力图生成方法之一。Grad-CAM的改进版,通过引入梯度加权的方式,提高了热力图的定位精度。基于类别的得分计算类激活图,对噪声具有更强的鲁棒性。基于特定层的特征图计算类激活图,可以灵活选择不同的层进行分析。通过上采样将低分辨率的特征图恢复到原始图像大小,提高了热力图的分辨率。基于特征图的特征向量进行PCA降维,得到更简洁的热力图。对Grad-CAM的进一步改进,通过加权平均的方式,提高了热力图的质量。基于积分梯度的方法,可以解释模型对输入的每个特征的贡献。

weixin_39818775的博客 2374

CodeForces 23A You're Given a String...(字符串处理)

Description You’re given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see

a novice 1821

AutoSAR系列讲解(实践篇)12.1-Diagnostics简介

主要概括性的讲解了诊断协议UDS和AutoSAR的诊断架构

雪云飞星的博客 1万+

Codeforces 23A You're Given a String...

A. You're Given a String... time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You're given a string of lower-cas...

aaa3201的博客 220

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

CodeForces 23A You're Given a String...

Description You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (

iCpC之旅 1012

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

CodeForces - 23A You're Given a String...

题目 由于题目中要求该字符子串出现两次所以直接从头开始进行匹配,第一个for代表该字符子串第一次出现,第二个for代表该字符子串第二次出现。通过max记录最大长度。 #include<iostream> #include<string> #include<cmath> using namespace std; int main( ) { string s; ...

qq_44722533的博客 239

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

codeforces 23A. You're Given a String...

巨水的一道题,100的数据O(n^3)复杂度30ms过。 蛋疼的是一开始读错题,substring字串认为是subsequence子序列。字串必须连续... 没啥好说的 #include #include #include #include #define max(a,b) ((a)>(b)?(a):(b)) #define INF 1000000005 char a[105]; int m

DBL 672

CodeForces 23A You're Given a String... (简单题)

题目类型  简单题 题目意思 输入 n (1 排名首先看得分情况 (比赛结果中 赢的一方得3分 输的一方得0分 | 平手情况两队各得一分) 如果得分相同就看 (进球数 - 失球数) 的值, 如果还是相同就看进球数 (都是大的排在前面) 解题方法 成功输入数据后, 统计数据, 最后排序输出即可 (详情看代码) 附 : STL(

yunyouxi0's blog 1019

CodeForces 23A-You're Given a String...

You're Given a String... time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You're given a string of lower-cas

wang_128的博客 595

洛谷 CF23A You‘re Given a String... 题解(CodeForces)

这个数是子串中最少出现两次的最长子串的长度。因为题目是字串,所以说直接双重。记录某个字符串出现过的次数。时,记录最长的长度。

lhschris的博客 422

LeetCode 之 string字符串一

1. Length of last word Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word does not exist,

coder 进阶的专栏 1万+

CodeForces - 23A You‘re Given a String...【水题】

题目链接:https://codeforces.com/contest/23/problem/A #include <iostream> #include <algorithm> using namespace std; static const int MAXN=100+10; char s[MAXN]; int ans; int main() { scanf("%s",s); for(int i=0;s[i];i++) for(int j=i+1;

inv0ker的博客 225

国庆10.2

A-Equality CodeForces - 1038A You are given a string s of length n, which consists only of the first k letters of the Latin alphabet. All letters in string s are uppercase. A subsequence of string s i...

莉莉莉的博客 366

You're given a string of lower-case Latin letters. Your task is to find the length of its longest su

C - You're Given a String...  代码:import java.util.Arrays;import java.util.Scanner;public class Main {public static void main(String[] args){  int count=1,k=0,max=0,i=0;  int[] sum=new int[100];  Sca...

L427630的博客 3367

国庆第二场训练赛

A You are given a string s of length n, which consists only of the first k letters of the Latin alphabet. All letters in string s are uppercase. A subsequence of string s is a string that can be deriv...

Allen的博客 371

2018国庆第二场个人赛

CodeForces - 1040A   A group of n dancers rehearses a performance for the closing ceremony. The dancers are arranged in a row, they've studied their dancing moves and can't change positions. For some...

ZCY的博客 331
上一篇: Longest Ordered Subsequence POJ - 2533(dp动态规划)
下一篇: 折线分割平面 HDU - 2050 (找规律)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值