Codeforces 844A Diversity
来源:互联网 发布:免费视频加密软件 编辑:程序博客网 时间:2024/06/06 09:18
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.
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).
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
yandex6
0
yahoo5
1
google7
impossible
In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters:{'a', 'h', 'o', 'y'}. To get5 different letters it is necessary to change one occurrence of'o' to some letter, which doesn't occur in the string, for example,{'b'}.
In the third test case, it is impossible to make 7 different letters because the length of the string is6.
水题
#include<bits/stdc++.h>using namespace std;int main(){string str;cin>>str;int n;cin>>n;int num[26]={0};int len=str.size();if(n>len){cout<<"impossible"<<endl;return 0;}for(int i=0;i<len;i++){num[str[i]-'a']++;}int ans=0;for(int i=0;i<26;i++){if(num[i]) ans++;}if(n<=ans) cout<<0<<endl;else cout<<n-ans<<endl;}
- Codeforces 844 A Diversity
- codeforces 844A Diversity
- Codeforces 844A Diversity
- Codeforces 844A Diversity
- codeforces 844A Diversity
- Codeforces AIM Tech Round 4 (Div. 2) A Diversity
- Codeforces AIM Tech Round 4 (Div. 2) A. Diversity
- CodeForces 844A Diversity (超级超级水唯一需要想得就是开个标记数组吧)
- diversity
- A Diversity-Promoting Objective Function for Neural Conversation Models
- AIM Tech Round 4 (Div. 2) A. Diversity
- diversity score
- PolyNet A pursuit of structural diversity in very deep networks(翻译笔记)
- CodeForces-a
- bnu 12872 Array Diversity
- UVALive 5990 Array Diversity
- Codeforces 903A A
- The Other Side of Diversity
- sed 模式空间
- js-递归,setTimeout回调函数的参数
- 解决Mac OS下pip安装ipython权限的问题
- Java静态代码块、构造代码块、构造函数
- 开发者论坛一周精粹(第十九期) :【重要事件】运维人员注意啦:NetSarang的Xmanager和Xshell多种产品被植入后门
- Codeforces 844A Diversity
- oracle在Linux(RedHat)下的安装教程-整理版
- Spring的jdbcTemplate操作
- RNA-seq数据处理流程(以胶质瘤数据为例)
- :Keil编译提示“File has been changed outside the editor, reload ”提示!
- winfrom 客户端调用服务器ftp图片进行显示问题
- QSS Subcontrol
- 使用JSONObject生成和解析json
- requests库入门-16-Session和Cookie