Super Reduced String
https://www.hackerrank.com/challenges/reduced-string/problem
He wants to reduce the string to its shortest length by doing a series of operations in which he selects a pair of adjacent lowercase letters that match, and then he deletes them.
aaabccddd->abccddd->abddd->abd
aabb->""
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
cin >> s;
for (int i = 0; i < (int)(s.length() - 1); i++){
if (!s.empty()&&s[i] == s[i + 1]){
s.erase(i, 2);
i = -1;//后面I还要加1,从头开始
}
}
if (s.empty()){
cout << "EMPTY" << endl;
}
else{
cout << s << endl;
}
return 0;
}
Super Reduced String的更多相关文章
- [源码]String StringBuffer StringBudlider(2)StringBuffer StringBuilder源码分析
纵骑横飞 章仕烜 昨天比较忙 今天把StringBuffer StringBulider的源码分析 献上 在讲 StringBuffer StringBuilder 之前 ,我们先看一下 ...
- String、StringBuffer、StringBuilder源码分析
利用反编译具体看看"+"的过程 1 public class Test 2 { 3 public static void main(String[] args) 4 { 5 int ...
- String类的基本用法与注意点,StringBuffer类的用法
package cn.hncu.day8; public class RegExpDemo { public static void main(String[] args) { String str ...
- super返回不过来
class Fruit { String color = "未确定颜色"; //定义一个方法,该方法返回调用该方法的实例 public Fruit getT ...
- JAVA构造方法,继承关系和SUPER关键字
SUPER可调用父类的构造方法,但要注意默认调用和参数调用. 同时,在继承类时,可以用SUPER调用其它非构造方法哟. class Test extends Object{ public Test() ...
- Java基础系列--this、super关键字
原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/8483623.html 一.概述 Java中this有两种用途,一种是用于指代当前对象,一种 ...
- Java——String对象
前言 实际上任何语言都没有提供字符串这个概念,而是使用字符数组来描述字符串.Java里面严格来说也是没有字符串的,在所有的开发里面字符串的应用有很多,于是Java为了应对便创建了String类这个字符 ...
- StringBuffer 详解 (String系列之3)
本章介绍StringBuffer以及它的API的详细使用方法. 转载请注明出处:http://www.cnblogs.com/skywang12345/p/string03.html StringBu ...
- String、StringBuilder、 StringBuffer 深入分析 源代码解析
java学习有一段时间了.但学习的东西都是框架等东西,java基础知识有点遗忘.所以重温一下java基础知识.写写文章里面有错的希望大家指正共同进步~~ 一.String 大家常常会说使用" ...
随机推荐
- 希尔排序——Java实现
一.排序思想 希尔排序(Shell’s Sort)是插入排序的一种,是直接插入排序算法的一种更高版本的改进版本. 把记录按步长gap分组,对每组记录采用直接插入排序方法进行排序: 随着步长逐渐减小,所 ...
- [SQL SERVER系列]工作经常使用的SQL整理,实战篇(二)[原创]
工作经常使用的SQL整理,实战篇,地址一览: 工作经常使用的SQL整理,实战篇(一) 工作经常使用的SQL整理,实战篇(二) 工作经常使用的SQL整理,实战篇(三) 接着上一篇“工作经常使用的SQL整 ...
- 通过学生-课程关系表,熟悉hive语句
通过学生-课程关系表,熟悉hive语句 1.在hive中创建以下三个表. create table student(Sno int,Sname string,Sex string,Sage int, ...
- redux基本使用
redux数据流向 基本使用
- 前端自动分环境打包(vue和ant design)
现实中的问题:有时候版本上线的时候,打包时忘记切换环境,将测试包推上正式服务器,那你就会被批了. 期望:在写打包的命令行的时候就觉得自己在打包正式版本,避免推包时候的,不确信自己的包是否正确. 既然有 ...
- 【Android】5.0 第一个工程学习——应用名称和图标修改、增加Buton控件、Toast信息提示
1.0 搞了很多天,eclipse只能开发Android6.0以前的版本,可能是因为谷歌不再针对eclipse更新了,在虚拟机Android6.0以上版本都无法构建,所以转到Android Studi ...
- SCI收录的期刊查询
SCI 收录的期刊查询(动态) 1.Science Citation Index (SCI)收录期刊查询地址:http://www.isinet.com/cgi-bin/jrnlst/jlopti ...
- 一个简单的 HTML 文档,带有最基本的必需的元素
<html> <head> <title>文档的标题</title> </head> <body> 文档的内容... ... & ...
- 【Leetcode】【Easy】Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- C++ 下使用curl 获取ftp文件
从http://curl.haxx.se/下载的win32版本的curl都不能使,#include <curl.h>后总是报错:external symbol ,意思就是没有链接到curl ...