首页 > 其他分享 >string reversal using stack【1月19日学习笔记】

string reversal using stack【1月19日学习笔记】

时间:2024-01-19 19:36:50浏览次数:32  
标签:string 19 复杂度 int reversal using stack

点击查看代码
//string reversal using stack
#include<iostream>
#include<stack>//stack from standard template library(STL)
using namespace std;

void reverse(char *c,int n) {
	stack<char> S;

	for (int i = 0; i < n; i++) {
		S.push(c[i]);//stack operation needs constant time
	}
	for (int i = 0; i < n; i++) {
		c[i] = S.top();
		S.pop();
	}
}//时间复杂度:O(n)
 //空间复杂度:O(n)//extra space

/*空间复杂度O(1)的算法:
        int i=start, j=end;
		while (i < j) {
			swap(c[i], c[j]);
			i++;
			j--;
		}
*/

int main() {
	char c[51];
	cin >> c;
	reverse(c, strlen(c));
	cout << c;
}

标签:string,19,复杂度,int,reversal,using,stack
From: https://www.cnblogs.com/whvivy/p/17975436

相关文章

  • 2024.1.19寒假每日总结10
    算法题:2809.使数组和小于等于x的最少时间-力扣(LeetCode)spark广播器场景:本地集合对象和分布式集合对象(RDD)进行关联的时候需要将本地集合对象封装为广播变量可以节省:1.网络IO的次数2.Executor的内存占用 ......
  • Codeforces Round 919 (Div. 2)
    目录写在前面ABCDE写在最后写在前面比赛地址:https://codeforces.com/contest/1920考试周突然发癫想打cf但是觉得肯定打不完所以拿小号打的。手速慢了没上大分呃呃A求出上下界来,再求被限制的数有多少个在区间内即可。///*By:Luckyblock*/#include<bits/stdc++.h>#de......
  • 海亮01/19数论专题
    海亮01/19数论专题个人题单T1P2522题意对于给出的\(n\)个询问,每次求有多少个数对\((x,y)\),满足\(a\lex\leb\),\(c\ley\led\),且\(\gcd(x,y)=k\),\(\gcd(x,y)\)函数为\(x\)和\(y\)的最大公约数。题解先差分下,问题改成计算\(\sum_{i=1}^n\sum_{j=1}^m[\gcd......
  • 1.19每日总结
    Python3解释器Linux/Unix的系统上,一般默认的python版本为2.x,我们可以将python3.x安装在 /usr/local/python3 目录中。安装完成后,我们可以将路径 /usr/local/python3/bin 添加到您的Linux/Unix操作系统的环境变量中,这样您就可以通过shell终端输入下面的命令来启动......
  • 2024.1.19
    9点26解决了一个第三方库require(xxxx)导致的vite4在build时报错Can'tfindvariable:requirehttps://github.com/vite-plugin/vite-plugin-commonjs《代码提取》三种等级,导出提取、函数提取和闭包提取。其中可以导出提取和闭包提取很有趣。其中导出提取解释了react-r......
  • CCPC-final 2019 Problem B - Infimum of Paths
    链接参考题解题意:求0->1路径上的数组成真小数最小值若最小路径无环,则长度\(\le\)n-1方法一从\(0\)开始,维护当前走到的点,每次都走边权(当前总体)最小的且\(v\)能到\(1\)的边,跑\(2n\)条边,顺便沿路维护走过的边权连\(1\rarr1\)代价为\(0\)的环,这样最后一定是在环......
  • Prime factorization of a number【1月19日学习笔记】
    点击查看代码//Primefactorizationofanumber#include<iostream>#include<cmath>usingnamespacestd;voidprimefactorization(intn){ for(inti=2;i<=sqrt(n);i++){//质因数(除去本身)只可能在根号n及其左侧 if(n%i==0){//i从2开始,短除法 intcou......
  • Adobe InDesign 2024 v19.1 (macOS, Windows) - 版面设计和桌面出版软件
    AdobeInDesign2024v19.1(macOS,Windows)-版面设计和桌面出版软件Acrobat、AfterEffects、Animate、Audition、Bridge、CharacterAnimator、Dimension、Dreamweaver、Illustrator、InCopy、InDesign、LightroomClassic、MediaEncoder、Photoshop、PremierePro、Adob......
  • Adobe InCopy 2024 v19.1 (macOS, Windows) - 编写和副本编辑软件
    AdobeInCopy2024v19.1(macOS,Windows)-编写和副本编辑软件Acrobat、AfterEffects、Animate、Audition、Bridge、CharacterAnimator、Dimension、Dreamweaver、Illustrator、InCopy、InDesign、LightroomClassic、MediaEncoder、Photoshop、PremierePro、AdobeXD......
  • Find all factors of a number【1月19日学习笔记】
    点击查看代码//Findallfactorsofanumber#include<iostream>#include<cmath>usingnamespacestd;voidFactors(intn){ int*factors=newint[n+1](); for(inti=1;i<=sqrt(n);i++){//检测一侧因子即可 if(n%i==0){ factors[i-1]=i;//问......