Codeforces CF#628 Education 8 C. Bear and String Distance
2016-12-02 12:07
615 查看
C. Bear and String Distance
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Limak is a little polar bear. He likes nice strings — strings of length n, consisting of lowercase English letters only.
The distance between two letters is defined as the difference between their positions in the alphabet. For example,
View Code
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Limak is a little polar bear. He likes nice strings — strings of length n, consisting of lowercase English letters only.
The distance between two letters is defined as the difference between their positions in the alphabet. For example,
1 #include <cstdio> 2 #include <cstring> 3 #include <string> 4 #include <iostream> 5 #include <algorithm> 6 using namespace std; 7 8 const int N = 100010; 9 int n, k; 10 char str ; 11 char ans ; 12 13 int main() { 14 scanf("%d%d", &n, &k); 15 scanf("%s", str); 16 memset(ans, 0, sizeof(ans)); 17 for(int i = 0; i < n; ++i) { 18 int dis = min(k, max(str[i] - 'a', 'z' - str[i])); 19 if(str[i] - 'a' >= dis) ans[i] = str[i] - dis; 20 else ans[i] = str[i] + dis; 21 k -= dis; 22 } 23 if(k) puts("-1"); 24 else printf("%s\n", ans); 25 return 0; 26 }
View Code
相关文章推荐
- Educational Codeforces Round 8 C. Bear and String Distance(贪心)
- Codeforces C - Bear and String Distance (贪心)
- Educational Codeforces Round 8 C. Bear and String Distance 贪心
- Codeforces 628 C. Bear and String Distance【贪心】
- CodeForces 628 C C - Bear and String Distance
- CF 628C --- Bear and String Distance --- 简单贪心
- CodeForces 628 C. Bear and String Distance(贪心)
- codeforces D. Bear and Tree Jumps
- Codeforces Round #356 D.Bear and Tower of Cubes DFS
- Codeforces Round #195 (Div. 2) A. Vasily the Bear and Triangle
- CF# Educational Codeforces Round 3 D. Gadgets for dollars and pounds
- 【Codeforces Round 354 (Div 2)C】【前缀和二分or双指针】Vasya and String ab序列最多改变k位置的最长同字符子串长度
- Codeforces Round #405 Div. 1 B. Bear and Tree Jumps
- Codeforces Round #378 (Div. 2)A. Grasshopper And the String
- 【Codeforces Round】351A - Bear and Game(水)
- Bear and Three Balls CodeForces - 653A
- Codeforces Round #226 (Div. 2) D. Bear and Floodlight
- Codeforces Round #356 (Div. 2) B. Bear and Finding Criminal 水题
- Bear and String Distance( 贪心)
- Codeforces Round #226 (Div. 2) C. Bear and Prime Numbers(素数筛法)