记一下STL的一个题
2024-09-04 18:18:42
A. Diversity
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible.
String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
Input
First line of input contains string s, consisting only of lowercase Latin letters (1 ≤ |s| ≤ 1000, |s| denotes the length of s).
Second line of input contains integer k (1 ≤ k ≤ 26).
Output
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
Examples
input
yandex
6
output
0
input
yahoo
5
output
1
input
7
output
impossible
#include <iostream>
#include<string>
#include<set>
#include<algorithm>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//set<int>ff;
int main(int argc, char** argv) {
set<int>ff;
string s;
int k;
cin>>s;
cin>>k;
int len=s.size() ; for(int i=;i<len;i++)
{
ff.insert(s[i]);
}
if(len<k)
printf("impossible\n");
else
{
int w=ff.size();
if(w>=k)
printf("0\n");
else
printf("%d\n",k-w);
}
return ;
}
最新文章
- linux下mono的安装与卸载
- AJAX-初学AJAX本地环境配置
- Sublime Text 2 中文 GBK 规范的配置 暨 解决中文乱码问题 简述
- eclipse错误:Unable to read workbench state. Workbench UI layout will be reset.XML document structures
- JavaScript 类
- 设计模式(六):Singleton 单件模式 -- 创建型模式
- Redis集群明细文档(转)
- javascript深入理解js闭包(个人理解,大神勿喷)
- 连续多个git提交发生了冲突时
- mysql修改数据库名
- 修改CentOS6.5默认主机名(root下操作)
- 【原创】Linux基础之常用命令
- angular bootstrap timepicker TypeError: Cannot set property &#39;$render&#39; of undefined
- Spring MVC中@JsonView的使用
- 在Mysql中查询两个时间段的差,可以是秒,天,星期,月份,年...
- shiroWeb项目-认证及MD5认证信息在页面显示(十)
- CSS3 Flex布局整理(三)-项目属性
- [Solution] The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path
- 添加网络ADB的方法(含以太网和无线)
- Eclipse中的特殊注释:TODO、XXX、FIXME