【字符串处理】UVALive - 6917 Decoding Baby Boos
2017-08-04 09:57
218 查看
Problem Description
给你T组数据,每组数据先给你一个串,只包含大写字母或者下划线。给你m组操作,每组操作有u, v两个大写字母,就是将串里面的所有字母v变成字母u
思路:把B变成A, 把A变成C,就相当于把 B变成C。那一个数组来存最后该字母变成那个字母
给你T组数据,每组数据先给你一个串,只包含大写字母或者下划线。给你m组操作,每组操作有u, v两个大写字母,就是将串里面的所有字母v变成字母u
思路:把B变成A, 把A变成C,就相当于把 B变成C。那一个数组来存最后该字母变成那个字母
#include<bits/stdc++.h> using namespace std; char s[1000055]; int main() { int T, m; char c1[2], c2[2]; int flag[30];//用来存,最后该字母变成那个字母 scanf("%d", &T); while(T--) { scanf("%s", s); for(int i = 0; i <= 26; i++)//初始化 flag[i] = i; scanf("%d", &m); while(m--) { scanf("%s %s", c1, c2); int u = c1[0] - 'A';//转换成整数 int v = c2[0] - 'A'; for(int i = 0; i <= 25; i++)//核心 { if(flag[i] == v)//原本flag[i]是字母v,现在让他变成字母u { flag[i] = u; } } } int len = strlen(s); for(int i = 0; i < len; i++) { if(s[i] >= 'A' && s[i] <= 'Z')//如果是大写字母 { int t = s[i] - 'A'; printf("%c", flag[t] + 'A');//输出变后结果 } else printf("%c", s[i]); } printf("\n"); } return 0; }
相关文章推荐
- Decoding Baby Boos UVALive - 6917-------降低时间复杂度
- UVALive 6917 Decoding Baby Boos(签到)
- UVALive - 4882 Parenthesis 表达式处理、字符串处理、栈
- UVA12897 - Decoding Baby Boos
- 模拟/字符串处理 UVALive 6833 Miscalculatio
- UVALive 6085|Chemistry|字符串处理
- Regionals 2014 >> Asia - Dhaka >> 6917 - Decoding Baby Boos
- UVA 12897 Decoding Baby Boos
- Immediate Decodability - UVa 644 字符串处理
- uva 475 - Wild Thing(字符串处理)
- Palindromes - UVa 401 字符串处理
- UVa 112|POJ 1145|Tree Summing|字符串处理|树的遍历
- Automatic Editing - UVa 10115 字符串处理
- uva 1339 Ancient Cipher(字符串处理)
- UVA 10905- Children's Game(sort处理string字符串)
- Hou Yi's secret(UVALive - 5714)枚举 精度处理
- UVA490 Rotating Sentences 字符串输入输出处理
- uva 10194 Football (aka Soccer)(字符串处理+sort排序)
- UVA 10941 - Words adjustment(BFS+字符串处理)
- UVA - 123 Searching Quickly 字符串处理