第五章 字符串专题 ---------------- 5.10 题解:神奇的回文串

经典编程题——回文问题 编程题:回文问题 马上要找工作了,最近一直在刷题,决定吧自己遇到的感觉比较好的题分享在博客里面,大家可以参考参考(其实我也不懂那些题好,那些题不好,哈哈)。 下面是最近做的一道关于回文的笔试题,大家看看: “回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。花花非常喜欢这种拥有对称美的回文串,生日的时候她得到两个礼物分别是字符串A和字符串B。现在她非常好奇有... 阅读详情

一、回文字符串:

1、题目:

判断一个字符串是否为 回文字符串。

思路:判断翻转后,是否与原串相同。

2、C++代码:

#include <iostream>
#include<algorithm>
using namespace std; 

bool isPalindrome(string src)
{
	if(src.empty())
	{
		return true;
	}
	string bef=src;
	reverse(src.begin(),src.end());
	
	return bef==src;
}
 
int main()
{
	string s="abcba";
	cout<<isPalindrome(s);
	
	return 0;
}

3、结果:

 

二、回文数:

1、题目:

输出所有的四位十进制 回文数。

2、C++代码:

#include <iostream>
using namespace std; 

int main()
{
	for(int i=1;i<10;i++)
	{
		for(int j=1;j<10;j++)
		{
			cout<<(i*1000+j*100+j*10+i)<<endl;
		}
	}
	
	return 0;
}

3、结果:

 

C++代码(回文单词,数据结构等) 本文件中有回文单词,电话号码管理系统,图书馆管理系统和数据结构C++实现。 立即下载

相关推荐

Python爬虫实战:巧用HEAD请求和Cookie令牌绕过沃尔玛反爬(附完整代码)

本文详细介绍了如何利用Python爬虫技术,通过HEAD请求和Cookie令牌绕过沃尔玛的反爬机制。文章深入解析了人机验证系统的运作原理,并提供了完整的工程化实现代码,包括令牌池设计、高并发架构和异常处理策略,帮助开发者高效采集电商数据。

weixin_29046035的博客 1022

回文字符串(C++对输入字符串的处理)--C++实现

题目如下: 给出一个长度不超过1000的字符串,判断它是不是回文(顺读,逆读均相同)的。 输入描述: 输入包括一行字符串,其长度不超过1000。 输出描述: 可能有多组测试数据,对于每组数据,如果是回文字符串则输出"Yes!”,否则输出"No!"。 输入 hellolleh helloworld 输出 Yes! No! C++实现: #include&lt;iostream...

zhang__shuang_的博客 8302

【华为2021校招】笔试题【通用硬件】

时间:2020/07/15 19:00 时长:60min 题型:40单选+5多选 难度:中等 考察范围:模电、数电、SI、EMC、电源、微机原理、计算机网络、材料

Jkcia的博客 4万+

生成英文回文串

生成英文回文串Description考虑有许多词语,现在希望找出所有三元组, 满足三元组内的词能够拼接成一个回文。 每一行, 按照拼接的顺序依次输出它们原来的位置,不同的行对应不同的三元组,输出时候要按从小到大顺序依次输出所有能够组成回文三元组的。考虑两个不同三元组A={a1,a2,a3},B={b1,b2,b3} (ai, bi是对应单词在输入单词序列中的序号),三元组的大小指的是第一个不同元素的

yangtengleo的博客 1433

C#实战:如何用Bartender 10.1实现动态打印与批量打印(附完整源码)

本文深入探讨了如何在C#项目中高效集成Bartender 10.1,实现企业级的动态打印与批量打印功能。文章提供了从环境配置、COM接口精讲、高可用打印服务类封装,到批量打印性能优化及生产环境部署的全套实战方案与源码,帮助开发者构建健壮、可维护的打印解决方案。

weixin_29290963的博客 452

Foxglove 介绍以及入门使用教程

Foxglove 是由Foxglove 工作室开发的一套工具集,包括和等组件。跨平台支持:可以在 Windows、macOS 和 Linux 上运行。多协议兼容:支持 ROS、ROS 2、CAN 数据以及其他自定义协议。丰富的可视化功能:可以绘制点云、轨迹、激光雷达数据、IMU 数据等。实时与离线模式:既可以实时监控机器人状态,也可以加载和回放记录的数据文件。Foxglove 的 3D 视图允许你以三维方式查看机器人的运动轨迹、传感器数据和其他几何信息。你可以旋转、缩放和平移视图以获得更好的观察角度。

zolty 1万+

题10:神奇的回文串

回文串:"acbca"、1211 package 字符串问题; public class case10_神奇的回文串 { public static void main(String[] args) { boolean res= isPalindrome("abcba"); System.out.println(res); palindromeNumber(); } public static boolean isPalindr

m0_66279156的博客 159

非易失存储器读写

24C256、IIC_SCL、IIC_SDA

CT_1104的专栏 3004

C++:最大回文字符串

方法一://最长回文子串 #include &lt;iostream&gt; using namespace std; //*s为字符串,n为字符串的长度 int LagPalindrome(char *str, int n) { int count = 0; int max = 0;//最长回文子串的长度 if (str == ...

FromNowOnUntilTheEnd 1447

ROS2前置基础教程 | 使用CMakeLists.txt编译ROS2节点

答案是有的,那就是cmake工具。cmake通过调用CMakeLists.txt直接生成Makefile。 2.新建CMakeLists.txt 在新建,输入下面内容。 3.编译代码 我们一般会创建一个新的目录,运行cmake并进行编译,这样的好处是不会显得那么乱。 创建好文件夹,接着运行cmake指令,代表到上级目录找。 运行完cmake你应该可以在build目录下看到cmake自动生成的Makefile了,接着就可以运行make指令进行编译 运行完上面的指令,就可以在build目录下发现节点了。ROS2

生活不止眼前的苟且 1万+

PX4与ROS协同仿真:从键盘控制到无人机自主飞行

本文详细介绍了如何搭建PX4与ROS协同仿真环境,实现从键盘控制到无人机自主飞行的完整流程。通过XTDrone项目整合PX4飞控、ROS通信框架与Gazebo物理引擎,逐步讲解环境配置、键盘控制实现原理,并深入剖析了迈向Offboard模式实现自主飞行的核心代码与数据流,为无人机算法开发与测试提供了安全的仿真沙盒。

weixin_29169899的博客 512

【Fifty Project - D22】

5.1的记录忘了发了~

qq_44267363的博客 654

45 - Android系统源码-crosvm 实战:基于 KVM 的 Rust 安全虚拟机监控器核心技术

摘要:crosvm 是 Google 开发的基于 KVM 的轻量级虚拟机监控器(VMM),采用 Rust 语言编写,专为 ChromeOS 和 Android 设计。其核心特点包括: 安全架构:通过 Rust 的内存安全特性和多进程隔离(每个设备运行在独立沙箱进程)大幅降低攻击面 性能优化:基于 KVM 的硬件虚拟化支持,结合异步 I/O (io_uring/epoll) 实现高效设备模拟 模块化设计:清晰的 trait 抽象层(Hypervisor/Vm/Vcpu)支持跨平台扩展 Android 集成

保持专注,保持热爱 236

C/C++编程题刷题:leetcode 1147. 段式回文

1147. 段式回文 段式回文 其实与 一般回文 类似,只不过是最小的单位是 一段字符而不是 单个字母。 举个例子,对于一般回文 "abcba" 是回文,而 "volvo" 不是,但如果我们把"volvo" 分为 "vo"、"l"、"vo" 三段,则可以认为 “(vo)(l)(vo)” 是段式回文(分为 3 段)。 给你一个字符串text,在确保它满足段式回文的前提下,请你返回段的最大数量k。 如果段的最大数量为k,那么存在满足以下条件的a_1, a_2, ..., a_k:...

Emotion的博客 275

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

C/C++编程题刷题:leetcode 680. 验证回文字符串 Ⅱ

680. 验证回文字符串 Ⅱ 难度简单247 给定一个非空字符串s,最多删除一个字符。判断是否能成为回文字符串。 示例 1: 输入: "aba" 输出: True 示例 2: 输入: "abca" 输出: True 解释: 你可以删除c字符。 class Solution { public: bool checkPalindrome(const string& s, int low, int high) { for (int i = low, j = .

Emotion的博客 381

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

LeetCode(C++)刷题计划:9-回文数

9-回文数 @Author:CSU张扬 @Email:csuzhangyang@gmail.com 2.1 解法一 1. 我们将该数字翻转得到的数字和原数字相等,此时它就是回文数。 2.2 解法二 1. 我们没有必要将整个数字翻转,只需要将后一半数字反转,再与前一半的数字相比较即可。

神奇小海螺的博客 9796

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

神奇的回文串《算法很美》

神奇的回文串 思路: 简单的要死,我就不说了! public class 神奇的回文串 { public boolean isPalindrome(String src){ if (StringUtils.isEmpty(src)){ return true; } //翻转后和自己相同---回文字符串 return src.equals(new StringBuilder(src).reverse().toS

罗彬桦的博客 182

C++刷题——2704: 回文素数

2704: 回文素数 /* Copyright (c) 2014, 烟台大学计算机学院 * All rights reserved. * 文件名称:test.cpp * 作者:陈丹妮 * 完成日期:2015年 5 月 26 日 * 版 本 号:v1.0 */ Description 输入一个数n,输出n以内所有的回文素数。回文素数,即既是素数,又是回文数,从前往后、从

nufangdongde的专栏 3173

第二章 :查找与排序---------递归、查找与排序补充

递归设计经验: ①、找重复(子问题) ②、找重复中的变化量-&gt;参数 ③、找参数变化趋势-&gt;设计出口 求n的阶乘: *找重复:n*(n-1)的阶乘,求n-1的阶乘是原问题的重复(规模更小)----子问题 *找变化:变化的量应该作为参数 *找边界 :出口 #include&lt;iostream&gt; using namespace std; /* **求n的...

Curtis’Blog 853

第一章:位运算-------输入浮点数,输出对应二进制数

第一章:位运算-------输入浮点数,输出对应二进制数 思想: 乘二取整,不需要反转。 #include&lt;iostream&gt; //#include&lt;algorithm&gt; using namespace std; int main(){ double input; cin&gt;&gt;input; string decimal=""; wh...

Curtis’Blog 545

第一章:位运算-------出现k次与出现1次

第一章:位运算-------出现k次与出现1次 问题: 数组中只有一个数出现了一次,其他的数都出现了k次,请输出只出现1次的数。 知识点: 2个相同的2进制数,做不进位加法,结果为0; 10个相同的10进制数,做不进位加法,结果为0; k个相同的k进制数,做不进位加法,结果为0; 思路: 将这些数,全部转换为k进制数,然后做不进位加,最后将结果转换为十进制数。 ...

Curtis’Blog 505

第四章:多维数组和矩阵 ------------- 4.4 找出边界为1的最大子方阵

找出边界为1的最大子方阵: 1、未优化的题解:(复杂度较高) //伪代码 max(A,N){ int n=N; while(n&gt;0){ for(i from 0 to N-1){ if(i+n&gt;N) break; l3: for(j from 0 to N-1){ if(j+n&gt;N) break; //i,...

Curtis’Blog 470

第三章 :查找与排序-------3.5快排之三指针分区法

快排之三指针分区法: e:指向第一个等于主元的元素; bigger:①、当所指元素&gt; 主元时,bigger--; ②、当所指元素&lt;=主元时;不动,等待与sp交换。 sp:扫描指针:①、&lt; 主元,sp所指元素和e所指元素交换,e++,sp++; ②、= 主元,sp++; ...

Curtis’Blog 429

第三章:查找与排序(下)----------- 3.9 最快效率求出乱序数组中第k小的数

最快效率求出乱序数组中第k小的数: 第k个元素:以尽量高的效率,求出一个乱序数组中按数值顺序的第k个元素值。 //伪代码: selectK(A,p,r,k){ q=partition(A,p,r); //主元下标 qK=q-p+1; //主元是第几个元素(排好序后) if(qK==k){ return A[q]; } else if(qK&gt;k){ return...

Curtis’Blog 419

第三章:查找与排序(下)----------- 3.22 总结:10种排序算法的对比分析

总结:10种排序算法的对比分析: *基础排序*: 冒牌排序: 描述:谁大谁上,每一轮都把最大的顶到天花板。 效率太低 O(n²)------掌握swap。 选择排序: 效率较低,但经常用它内部的内部循环方式来找最大值和最小值------怎么一次性求出数组的最大值和最小值。 O(n²) 插入排序: 虽然平均效率低,...

Curtis’Blog 406

第二章 :查找与排序-------2.10常见函数的复杂度计算

常见函数的复杂度计算: 算法复杂度/拥有的时间 1s可以处理的规模 lg(n) 2^(100000000) n 100000000 n² 10000 n³ 500 2^n 27 复杂度\ n的规模-&gt; 100000000 lg(n) 27/(10^8) n...

Curtis’Blog 397
上一篇: 第五章 字符串专题 ---------------- 5.9 题解:去掉字符串中连接出现的k次的0
下一篇: 第五章 字符串专题 ---------------- 5.11 题解:最短摘要的生成
Estrellas_
博客等级 码龄9年 273粉丝 233原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址