ZOJ 1068 P,MTHBGWB
题目大意:给定一个字符串,先用Morse Code编码,把编码倒序,再解码成字符串。现给定处理后的字符串,求原始信息。
解法:用C++String类的函数。每次读入一个字符,就在string后面接上,并且保存字符对应morse码的长度。这里要声明一下,真正的morse码也是有句号、问号这些常用标点符号的,但不是题目里给出的那种形式。比如,句号是“.-.-.-”。
参考代码:
#include<iostream>
#include<string>
using namespace std; string code[30]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---",
"-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-",
"...-",".--","-..-","-.--","--..","..--",".-.-","---.","----"}; int main(){
int i,j,k,len,n,num[100],cases=0;
string str,ss; cin>>n;
while(n--){
cases++;
cin>>str;
len=str.length();
i=0;
string morse="";
while(i<len){
if(str[i]>64&&str[i]<91){
morse.append(code[str[i]-'A']);
num[len-1-i]=code[str[i]-'A'].size();
}
else{
switch(str[i]){
case '_': morse.append("..--");break;
case ',': morse.append(".-.-");break;
case '.': morse.append("---.");break;
case '?': morse.append("----");break;
}
num[len-1-i]=4;
}
i++;
}
i=j=0;
while(i<len){
k=0;
ss=morse.substr(j,num[i]);
j+=num[i];
if(ss=="..--"){str[i++]='_';continue;}
if(ss==".-.-"){str[i++]=',';continue;}
if(ss=="---."){str[i++]='.';continue;}
if(ss=="----"){str[i++]='?';continue;}
while(k<26){
if(ss.compare(code[k])==0){
str[i++]=k+'A';
break;
}
k++;
}
}
cout<<cases<<": "<<str<<endl; } return 0;
}
ZOJ 1068 P,MTHBGWB的更多相关文章
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom /ZOJ 1291 MPI Maelstrom (最短路径)
POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom ...
- ZOJ题目分类
ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
随机推荐
- C++string的操作
#include <iostream> using namespace std; int main() { //initilization string str("abc.ddd ...
- a Makefile
obj-m += showpid.o obj-m += ps.o all: make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) mo ...
- windows下将磁盘脱机,并在"我的电脑"下显示
方案一: .右键单击"我的电脑". 2.打开:管理-磁盘管理. 3.在右边出现的磁盘分区里,你想隐藏的分区上右键单击“更改驱动器名和路径”. 4.出现一个对话框,点击“删除”. 5 ...
- iframe和form表单的target应用简单例子
iframe和form表单的target属性 Problem: 刷新主页面中的其中一个iframe,其他内容不变 Solution: main.jsp <body onload=" ...
- (转)深入浅出 iOS 之生命周期
原文:http://www.cocoachina.com/applenews/devnews/2011/0817/3129.html 深入浅出 iOS 之生命周期 发布于:2011-08-17 10: ...
- ResultSet结果集判断是否为空
目前亲测过能用的一个方法是: if(rs.next())//当前行有内容 { msg2 = "有这个活动!"; } else //rs对象为空表示查无此活动 { msg2 = &q ...
- 自己搭建Wifi Pineapple Mark V
创业搞得自己很累,不过一切都是值得的.抽空写下文章,确实好久未更新了. 前段时间由于项目需要,所以就折腾了下wifi pineapple.时间间隔有点久,根据回忆记录下. 淘宝货:TP-Link TL ...
- 51 nod 机器人走方格
从一个长方形的方格的右上角 走到 左下角 , 问一共有多少种不同的路线可以达到 . #include<stdio.h> #include<string.h> #include& ...
- PHP_Const
PHP_Const 常量 规则: 1 总是大写 2 A-Z 及 从127-255的ASCII字符 3 全局范围 4 用define函数定义 5 只能包含标量数据 如Boolean integer fl ...
- 15、SQL基础整理(视图)
视图 即虚拟表 系统-右键-新建视图 编辑前200行 select *from studentscore 代码创建法: create view studentscore as select stude ...