UVa 10950 - Bad Code
题目:有一种编码方式。串仅仅有小写字母构成,每一个小写字母相应一个数字,如今给你妆化后的数字串,
问有多少个原串与之相应,注意数字串里可能有一个前导0。
分析:搜索。按字母顺序存储映射表,按字母顺序匹配搜索就可以。
说明:注意最多仅仅输出前100个。
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio> using namespace std; char buf[101]; int code[128];
char maps[128][5];
char letter[128]; int Count = 0;
char save[101];
void dfs(int s, int d, int n, int m)
{
if (Count == 100) return;
char word[101];
if (s == n) {
save[d] = 0;
printf("%s\n",save);
Count ++;
return;
}
for (int k = 0 ; k < m ; ++ k) {
int count = 0;
for (int i = s ; i < n ; ++ i) {
word[count ++] = buf[i];
word[count] = 0;
if (!strcmp(word, maps[k]) || (word[0] == '0' && !strcmp(word+1, maps[k]))) {
save[d] = letter[k];
dfs(i+1, d+1, n, m);
}
}
}
} int main()
{
int n,t = 1;
char c;
while (~scanf("%d",&n) && n) {
memset(code, 0, sizeof(code));
for (int i = 0 ; i < n ; ++ i) {
getchar();
scanf("%c",&c);
scanf("%d",&code[c]);
} int count = 0;
for (int i = 'a' ; i <= 'z' ; ++ i)
if (code[i] > 0 && code[i] < 100) {
letter[count] = i;
if (code[i] > 9) {
maps[count][0] = code[i]/10 + '0';
maps[count][1] = code[i]%10 + '0';
maps[count][2] = 0;
}else {
maps[count][0] = code[i] + '0';
maps[count][1] = 0;
}
count ++;
} scanf("%s",buf);
printf("Case #%d\n",t ++);
Count = 0;
dfs(0, 0, strlen(buf), count);
printf("\n");
}
return 0;
}
UVa 10950 - Bad Code的更多相关文章
- UVa——1593Alignment of Code(string重定向+vector数组)
UVA - 1593 Alignment of Code Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & ...
- uva 交叉染色法10004
鉴于网上讲交叉染色的资料比较少,于是我把我自己的心得与方法贴出来,方便与大家共同进步. 二分图: 百度百科传送门 wiki百科传送门 判断一个图是否为二分图可以用交叉染色的方法来判断,可以用BFS,也 ...
- UVA 11754 - Code Feat(数论)
UVA 11754 - Code Feat 题目链接 题意:给定一个c个x, y1,y2,y3..yk形式,前s小的答案满足s % x在集合y1, y2, y3 ... yk中 思路:LRJ大白例题, ...
- UVA 12436 - Rip Van Winkle's Code(线段树)
UVA 12436 - Rip Van Winkle's Code option=com_onlinejudge&Itemid=8&page=show_problem&cate ...
- UVA 11557 - Code Theft (KMP + HASH)
UVA 11557 - Code Theft 题目链接 题意:给定一些代码文本.然后在给定一个现有文本,找出这个现有文本和前面代码文本,反复连续行最多的这些文本 思路:把每一行hash成一个值.然后对 ...
- Uva 11754 Code Feat
题意概述: 有一个正整数$N$满足$C$个条件,每个条件都形如“它除以$X$的余数在集合$\{Y_1, Y_2, ..., Y_k\}$中”,所有条件中的$X$两两互质, 你的任务是找出最小的S个解. ...
- UVA 11754 Code Feat (枚举,中国剩余定理)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud C Code Feat The government hackers at C ...
- UVa 740 - Baudot Data Communication Code
称号:目前编码,他们shift键被按下,并提出,对应的两个编码,其中,2相应的编码shift操作. 给你适当的编码值.寻求相应的字符串. 分析:模拟.字符串. 简单题,标记shift的升降分类处理就可 ...
- Uva 12436 Rip Van Winkle's Code
Rip Van Winkle was fed up with everything except programming. One day he found a problem whichrequir ...
随机推荐
- Windows 如何使用telnet管理虚拟机Linux
Linux远程登录的工具很多,如putty,SecureCRT…… 其实借助Windows的telnet工具就可以在命令提示符轻松的登录到Linux系统进行操作了. 虽然telnet很简单,但还是要进 ...
- C#筆記--DataGridView使用
1.databingcomplete 当数据源的内容更改时,或者当 DataSource.DataMember 或 BindingContext 属性的值更改时,会引发此事件. 例如,如果要基于内容更 ...
- VS2017 ATL创建ActiveX编程要点
VS2017 ATL创建ActiveX控件编程要点: 一.创建vs项目需要安装器visual studio installer中: 安装 visual studio扩展开发中的 用于x86和x64的V ...
- Less用法注意事项
(1)引入顺序 引入你的 .less 样式文件的时候要设置 rel 属性值为 “stylesheet/less”: <link rel="stylesheet/less" t ...
- 2.10.2 section元素
section元素 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> & ...
- note for git
1.download https://git-for-windows.github.io/ 2.command add file to git: git add filename & git ...
- mui.openWindow的html5+和web传参的兼容
mui.openWindow兼容web&plus环境下的页面传参 背景介绍 刚刚好要写个微信公众号和html5+兼容的项目 发现总是用localStorage传参不是事啊 太不优雅了 想了想还 ...
- mysql查询排名
student_work表 student_info表 sql语句:按grade从高到低排名 结果:
- *** 红包书用法 及 ubuntu全局配置
使用教程 http://go.wasai.org/sswiki https://home.maysoul.com/wiki/doku.php?id=shadowsocks ubuntu使用教程 htt ...
- UVa 548 树(已知其中两种遍历, 还原树)
题意: 给出后序遍历和先序遍历, 还原一棵树, 然后求出从根节点到叶子的最小路劲和. 分析: 已知后序遍历, 那么后序的最后一个节点就是根节点, 然后在中序中找到这个节点, 它的左边就是左子树, 它的 ...