Alien And Password

Time Limit: 2000/1000ms (Java/Others)

Problem Description:

Alien Fred wants to destroy the Earth, but he forgot the password that activates the planet destroyer.
You are given a string S. Fred remembers that the correct password can be obtained from S by erasing exactly one character.
Write a program to calculate the number of different passwords Fred needs to try.
0)
"A"
Answer: 1
In this case, the only password Fred needs to try is an empty string.
1)
"ABA"
Answer: 3
The following three passwords are possible in this case: "BA", "AA", "AB".
2)
"AABACCCCABAA"
Answer: 7
3)
"ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"
Answer: 1
Regardless of which character we erase, we will always obtain the same string. Thus there is only one possible password: the string that consists of 49 'Z's.

Input:

The input contains multiple cases.Each case contains a string(length less than 100).

Output:

For each case,output the answer of the problem.

Sample Input:

A
ABA
AABACCCCABAA
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

Sample Output:

1
3
7
1
解题思路:使用string.erase(pos,num),删除从pos索引开始的num个字符, 返回*this,为了不改变目标字符串str,所以用临时的字符串obj保存删除str中每个位置上的字符前的字符串str,这样每次删除后都将其放在容器set中,最后输出容器中元素的个数即可,水过!
AC代码:
 #include<bits/stdc++.h>
using namespace std;
int main(){
string str,obj;set<string> st;
while(cin>>str){
st.clear();//清空
for(size_t i=;i<str.length();++i){
obj=str;st.insert(obj.erase(i,));
}
cout<<st.size()<<endl;
}
return ;
}

ACM_Alien And Password的更多相关文章

  1. 打开程序总是会提示“Enter password to unlock your login keyring” ,如何成功关掉?

    p { margin-bottom: 0.1in; line-height: 120% } 一.一开始我是按照网友所说的 : rm -f ~/.gnome2/keyrings/login.keyrin ...

  2. your password has expired.to log in you must change it

    今天应用挂了,log提示密码过期.客户端连接不上. 打开mysql,执行sql语句提示密码过期 执行set password=new password('123456'); 提示成功,但客户端仍然连接 ...

  3. MySql Access denied for user 'root'@'localhost' (using password:YES) 解决方案

    关于昨天下午说的MySQL服务无法启动的问题,解决之后没有进入数据库,就直接关闭了电脑. 今早打开电脑,开始-运行 输入"mysql -uroot -pmyadmin"后出现以下错 ...

  4. [上架] iOS "app-specific password" 上架问题

    当你的 Apple ID 改用双重认证密码时,上架 iOS App 需要去建立一个专用密码来登入 Apple ID 才能上架. 如果使用 Application Loader 上传时,得到这个讯息: ...

  5. [LeetCode] Strong Password Checker 密码强度检查器

    A password is considered strong if below conditions are all met: It has at least 6 characters and at ...

  6. mysql 错误 ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number 解决办法

    MySQL创建用户(包括密码)时,会提示ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number: 问题原因: ...

  7. phpmyadmin #1045 - Access denied for user 'root'@'localhost' (using password: NO)

    phpmyadmin访问遇到1045问题 #1045 - Access denied for user 'root'@'localhost' (using password: NO) 解决办法 找到p ...

  8. 保留password模式文本框textbox内的数据不丢失。

    在asp.net 2.0环境下,使用textbox,提交到服务器再传回,如果textbox是password模式的,那么textbox内的密码(星号),就没有了! protected override ...

  9. Windows mysql提示:1045 access denied for user 'root'@'localhost' using password yes

    Windows mysql提示:1045 access denied for user 'root'@'localhost' using password yes http://blog.csdn.n ...

随机推荐

  1. POJ 2142 TheBalance 模线性方程求解

    题目大意: 就是将两种砝码左右摆放,能够在物品放置在天平上时保持平衡 很容易得到 ax + by = t的模线性方程 按题目要求,希望首先满足 |x| + |y| 最小 , 如果有多种情况,再满足所有 ...

  2. [luoguP1433] 吃奶酪(DP || Dfs)

    传送门 深搜加剪纸可A(O(玄学) 1274ms) ——代码 #include <cmath> #include <cstdio> #include <iostream& ...

  3. python整数转ASCII码

    # *-* coding:utf-8 *-* import binascii data = [1441465642, 251096121, -870437532, -944322827, 647240 ...

  4. poj 2823 二分法+单调队列

    #include<stdio.h> #include<string.h> #define N  1100000 int a[N]; int fmin[N],fmax[N]; i ...

  5. 20180725利用pmm监控管理mysql

    转自:https://www.percona.com/doc/percona-monitoring-and-management/architecture.html 报警机制https://www.p ...

  6. project处理 InteropServices.COMException 异常

    project文件无法上传,在上传中的hangfire出现了这个异常 System.Runtime.InteropServices.COMException 这个是因为website的权限是IUser ...

  7. 符号变换引擎(Symbol Transform Engine - STE)

    在写编译器的过程中.我意识到编译事实上是一种符号变换,比方C语言编译成机器码,事实上是C源代码文件里的符号变换成EXE的16进制符号,这和中文翻译成英语的语言翻译器没什么差别. 每一个程序猿都有自己喜 ...

  8. golang中channels的本质详解,经典!

    原文:https://www.goinggo.net/2014/02/the-nature-of-channels-in-go.html The Nature Of Channels In Go 这篇 ...

  9. 友盟 个推 微信sdk spring boot

    友盟 个推 微信sdk spring boot ngix mongodb memory cache

  10. Spark SQL CLI 实现分析

    背景 本文主要介绍了Spark SQL里眼下的CLI实现,代码之后肯定会有不少变动,所以我关注的是比較核心的逻辑.主要是对照了Hive CLI的实现方式,比較Spark SQL在哪块地方做了改动,哪些 ...