题目:有一种编码方式。串仅仅有小写字母构成,每一个小写字母相应一个数字,如今给你妆化后的数字串,

问有多少个原串与之相应,注意数字串里可能有一个前导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的更多相关文章

  1. UVa——1593Alignment of Code(string重定向+vector数组)

    UVA - 1593 Alignment of Code Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & ...

  2. uva 交叉染色法10004

    鉴于网上讲交叉染色的资料比较少,于是我把我自己的心得与方法贴出来,方便与大家共同进步. 二分图: 百度百科传送门 wiki百科传送门 判断一个图是否为二分图可以用交叉染色的方法来判断,可以用BFS,也 ...

  3. UVA 11754 - Code Feat(数论)

    UVA 11754 - Code Feat 题目链接 题意:给定一个c个x, y1,y2,y3..yk形式,前s小的答案满足s % x在集合y1, y2, y3 ... yk中 思路:LRJ大白例题, ...

  4. UVA 12436 - Rip Van Winkle&#39;s Code(线段树)

    UVA 12436 - Rip Van Winkle's Code option=com_onlinejudge&Itemid=8&page=show_problem&cate ...

  5. UVA 11557 - Code Theft (KMP + HASH)

    UVA 11557 - Code Theft 题目链接 题意:给定一些代码文本.然后在给定一个现有文本,找出这个现有文本和前面代码文本,反复连续行最多的这些文本 思路:把每一行hash成一个值.然后对 ...

  6. Uva 11754 Code Feat

    题意概述: 有一个正整数$N$满足$C$个条件,每个条件都形如“它除以$X$的余数在集合$\{Y_1, Y_2, ..., Y_k\}$中”,所有条件中的$X$两两互质, 你的任务是找出最小的S个解. ...

  7. UVA 11754 Code Feat (枚举,中国剩余定理)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud C Code Feat   The government hackers at C ...

  8. UVa 740 - Baudot Data Communication Code

    称号:目前编码,他们shift键被按下,并提出,对应的两个编码,其中,2相应的编码shift操作. 给你适当的编码值.寻求相应的字符串. 分析:模拟.字符串. 简单题,标记shift的升降分类处理就可 ...

  9. Uva 12436 Rip Van Winkle&#39;s Code

    Rip Van Winkle was fed up with everything except programming. One day he found a problem whichrequir ...

随机推荐

  1. vultr服务器L2TP搭建

    前期准备,购买外服,选择vultr服务商,可选择洛杉矶的,系统为Ubuntu 14.04 x64 一.安装L2TP/IPSec wget --no-check-certificate https:// ...

  2. 3D旋转矩阵的推导过程

    3D旋转矩阵的推导过程 包含平移的线性变换称作仿射变换,3D中的仿射变换不能用 3 x 3 矩阵表达,必须使用4 x 4矩阵. 一般来说,变换物体相当于以相反的量变换描述这个物体的坐标系.当有多个变换 ...

  3. leetcode_684. Redundant Connection

    https://leetcode.com/problems/redundant-connection/ 一个无向图,n个顶点有n条边,输出一条可以删除的边,删除后使得图成为一棵树.可以使用并查集解决. ...

  4. slover层解读

    void Solver<Dtype>::UpdateSmoothedLoss(Dtype loss, int start_iter, int average_loss) { if (los ...

  5. NOIP2016玩具迷题

    题目大意就不说了,反正水水就过了. 主要在于找01关系. 代码: #include<cstdio> int n,m; struct node { ]; int f; }a[]; int m ...

  6. ID字段不采用数据库自增长的几点理由

    一个小程序,最初采用了 SqlServer 数据库,后来为了便于部署,转而采用了 Firebird 嵌入式数据库.在重构代码转到 Firebird 的过程中,对“数据实体的数据表的ID字段是否应该使用 ...

  7. linux性能优化cpu-01性能指标

    学习性能优化的第一步,一定要了解性能指标. 性能指标是什么? 当我们看到性能指标时一定先想到“高并发”.“响应快”,这个两个指标也对应着性能优化的两个核心指标—— “吞吐率”和“低延迟”. 这两个指标 ...

  8. Python之字符串计算(计算器)

    Python之字符串计算(计算器) import re expression = '-1-2*((60+2*(-3-40.0+42425/5)*(9-2*5/3+357/553/3*99/4*2998 ...

  9. linux虚拟环境搭建

    一.virtualenv的安装与使用 1.安装virtualenv pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple virtualen ...

  10. LeetCode(61) Rotate List

    题目 Given a list, rotate the list to the right by k places, where k is non-negative. For example: Giv ...