ACM_Alien And Password
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的更多相关文章
- 打开程序总是会提示“Enter password to unlock your login keyring” ,如何成功关掉?
p { margin-bottom: 0.1in; line-height: 120% } 一.一开始我是按照网友所说的 : rm -f ~/.gnome2/keyrings/login.keyrin ...
- your password has expired.to log in you must change it
今天应用挂了,log提示密码过期.客户端连接不上. 打开mysql,执行sql语句提示密码过期 执行set password=new password('123456'); 提示成功,但客户端仍然连接 ...
- MySql Access denied for user 'root'@'localhost' (using password:YES) 解决方案
关于昨天下午说的MySQL服务无法启动的问题,解决之后没有进入数据库,就直接关闭了电脑. 今早打开电脑,开始-运行 输入"mysql -uroot -pmyadmin"后出现以下错 ...
- [上架] iOS "app-specific password" 上架问题
当你的 Apple ID 改用双重认证密码时,上架 iOS App 需要去建立一个专用密码来登入 Apple ID 才能上架. 如果使用 Application Loader 上传时,得到这个讯息: ...
- [LeetCode] Strong Password Checker 密码强度检查器
A password is considered strong if below conditions are all met: It has at least 6 characters and at ...
- 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: 问题原因: ...
- phpmyadmin #1045 - Access denied for user 'root'@'localhost' (using password: NO)
phpmyadmin访问遇到1045问题 #1045 - Access denied for user 'root'@'localhost' (using password: NO) 解决办法 找到p ...
- 保留password模式文本框textbox内的数据不丢失。
在asp.net 2.0环境下,使用textbox,提交到服务器再传回,如果textbox是password模式的,那么textbox内的密码(星号),就没有了! protected override ...
- 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 ...
随机推荐
- this与const
在普通非const成员函数中,this是const指针,而在const成员函数中,this是const对象的const指针. class Foo { Foo& get_self1(void) ...
- 日期工具类 DateTools
为了跟其他日期工具类进行区分起名字DateTools public class DateTools { /** The DAT e_ forma t1. */ public static String ...
- JavaScript学习总结(12)——2016 年 7 个顶级 JavaScript 框架
当涉及到Web开发时,JavaScript框架往往是一些开发人员和企业最受欢迎的平台.可能,你有机会尝试过一两个顶级的JavaScript框架,但你仍然有点不确定哪个才是最佳的最值得掌握的,或者哪个值 ...
- mongodb数据库的一些常用命令列表
超级用户相关:use admin #增加或修改用户密码db.addUser(ixigua,'pwd') #查看用户列表db.system.users.find() #用户认证db.auth(ixigu ...
- CodeForces 367E Sereja and Intervals
CodeForces 3 67E (109 + 7). Two ways are considered distinct if there is such j(1 ≤ j ≤ n), that the ...
- zoj——1311 Network
Network Time Limit: 2 Seconds Memory Limit: 65536 KB A Telephone Line Company (TLC) is establis ...
- hdu 1247 Hat’s Words(从给的单词中找hat's word 并按字典序输出)
1.在使用mp[key]的时候它会去找键值为key的项,假设没有,他会自己主动加入一个key的项,再把value赋值为对应的初始值(value是int的话赋值为0,string的话赋值为空).所以假设 ...
- PHP array_merge()
定义和用法 array_merge() 函数把两个或多个数组合并为一个数组. 如果键名有重复,该键的键值为最后一个键名对应的值(后面的覆盖前面的).如果数组是数字索引的,则键名会以连续方式重新索引. ...
- Codeforces 577E Ann and Half-Palindrome 字典树
题目链接 题意: 若一个字符串是半回文串.则满足第一位和最后一位相等, 第三位和倒数第三位相等.如此类推. 给定一个字符串s,输出s的全部子串中的半回文串字典序第k大的 字符串. good[i][j] ...
- 不能不说的C#特性-表达式树
不能不说的C#特性-表达式树 2008-09-18 00:00 by 横刀天笑, 17112 阅读, 14 评论, 收藏, 编辑 最近发生了很多很多事情,频繁的搬家.工作上的事情也挺多的,所以博客更新 ...