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 ...
随机推荐
- PPTP的搭建
一.准备 1.检查是否支持pptp modprobe ppp-compress-18 && echo yes yes支持 2.是否开启tun cat /dev/net/tun 返回ca ...
- MFC线程获取主窗口句柄
CWnd* h_q = AfxGetApp()->GetMainWnd(); //获取主窗口的句柄
- opencv读图片错误,已解决
could not loag image... terminate called after throwing an instance of 'cv::Exception' what(): OpenC ...
- 第2节 mapreduce深入学习:14、mapreduce数据压缩-使用snappy进行压缩
第2节 mapreduce深入学习:14.mapreduce数据压缩-使用snappy进行压缩 文件压缩有两大好处,节约磁盘空间,加速数据在网络和磁盘上的传输. 方式一:在代码中进行设置压缩 代码: ...
- Educational Codeforces Round 58 (Rated for Div. 2) (前两题题解)
感慨 这次比较昏迷最近算法有点飘,都在玩pygame...做出第一题让人hack了,第二题还昏迷想错了 A Minimum Integer(数学) 水题,上来就能做出来但是让人hack成了tle,所以 ...
- 算法竞赛入门经典5.2 STL初步
1. 排序和检索,学会使用sort排序,以及low_bound函数 Raju and Meena love to play with Marbles. They have got a lot of m ...
- Mysql 字符函数详解
MySql 所有字符串函数函数详解 ASCII(str) 返回str最左边第一位字符的ASCII编码,如果str为空,则返回 0 .如果str为NULL,则返回NULL -- 只返回a的ASCII编码 ...
- shell脚本、if语句、for循环语句
shell在shell脚本中,如果用户不输入东西,系统不自动退出,this is a bug!文件测试语句:-d -f -r -w -x -e逻辑测试语句:“&&”与(同时满足) “| ...
- Buffer.from(str[, encoding])
Buffer.from(str[, encoding]) Node.js FS模块方法速查 str {String} 需要编码的字符串 encoding {String} 编码时用到,默认:'utf8 ...
- leetcode-169求众数
求众数 思路: 记录每个元素出现的次数,然后查找到众数 代码: class Solution: def majorityElement(self, nums: List[int]) -> int ...