cf554A使用set和string解决字符串重复问题
来源:互联网 发布:linux vi 删除一行 编辑:程序博客网 时间:2024/05/16 06:52
这道题当时自己A的,比较麻烦,而且想了好久,还用了unique()函数去重,比较麻烦,而且WA了一发
自己的代码:
#include<stdio.h>#include<math.h>#include<iostream>#include<algorithm>#include<cstring>#include<string>#include<cctype>#include<cassert>#include<cmath>#include<algorithm>#include<cctype>#include<map>#include<vector>#include<stack>#include<queue>#include<set>#include<cstdlib>using namespace std;#define LL long longint main(){ char s[25],b[25]; while(gets(s)) { int l=strlen(s); memcpy(b,s,sizeof(s)); sort(b,b+l); int cc=unique(b,b+l)-b; int num=(26-cc)*(l+1); num+=cc*l; num=num-(l-cc); cout<<num<<endl; } return 0;}看了题解之后,题解使用了JAVA中的hashset和string写的,使用了hashset的自动去重功能,直接在使用string连接暴力一发由于自己对JAVA不太熟悉,手打了一发set和string写的,比较简单,代码:
#include<iostream>#include<cstdio>#include<algorithm>#include<set>#include<string>using namespace std;int main(){ string s;while(cin>>s) { set<string> a; for(int i=0;i<=s.length();i++) for(char c='a';c<='z';c++) { a.insert(s.substr(0,i)+c+s.substr(i)); } cout<<a.size()<<endl; }}
0 0
- cf554A使用set和string解决字符串重复问题
- 使用cookie解决重复投票的问题
- 使用UUID解决重复提交问题
- 用set和data解决运输问题
- java hashcode() 和equals()详解 以及set不能重复问题
- Set剔除重复数据和List的排序问题
- string字符串和char字符串的使用
- set和data解决运输问题2(使用.txt传递数据)
- 字符串类string使用的相关问题
- 字符串重复问题
- mysql 使用set names 解决乱码问题的原理
- mysql 使用set names 解决乱码问题的原理
- mysql 使用set names 解决乱码问题的原理
- mysql 使用set names 解决乱码问题的原理
- mysql 使用set names 解决乱码问题的原理
- Redis: 使用Sorted Set 解决游戏中有关排行问题
- mysql 使用set names 解决乱码问题的原理
- vim 使用技巧 set paste 解决粘贴乱序问题
- oracle数据库在删掉全部重做日志后如何进行恢复
- xib autolayout 左到右依次按内容长度排列
- Java连接SQL Server 2000 (version 8)
- NSTimer/定时器
- PARSEC在CentOS6.5 版本的linux系统下安装过程
- cf554A使用set和string解决字符串重复问题
- 正则表达式替换两个特殊字附串中的字附串
- TCP/IP传输层,你懂多少?
- Android 状态栏消息推送 BroadcastReceiver的使用
- Hadoop入门系列(4) -- MapReduce详解
- Generate Parentheses
- How to use interfaces in Go
- 欢迎使用CSDN-markdown编辑器
- struts2工作流程