链接:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1281
原题:
You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way. Because of pending patent issues we will not discuss in detail how the strings are generated and inserted
into the original message. To validate your method, however, it is necessary to write a program that checks if the message is really encoded in the final string.
Given two stringssandt, you have to decide whethersis a subsequence oft, i.e. if you can remove characters fromtsuch that the concatenation of the remaining characters iss.
Input Specification
The input contains several testcases. Each is specified by two stringss, tof alphanumeric ASCII characters separated by whitespace. Input is terminated by EOF.
Output Specification
For each test case output, ifsis a subsequence oft.
Sample Input
sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter
Sample Output
Yes
No
Yes
No
分析与总结:
简单题,直接判断一个字符串是否是另一个字符串的子串。
代码:
/*
* UVa: 10340 - All in All
* Time: 0.008s
* Author: D_Double
*/
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char str1[1000000], str2[1000000];
bool judge(){
int pos=0, i;
for(i=0; i<strlen(str1); ++i){
bool flag=false;
while(pos < strlen(str2)){
if(str2[pos]==str1[i])
break;
++pos;
}
if(pos==strlen(str2)) return false;
++pos;
}
if(i==strlen(str1)) return true;
return false;
}
int main(){
while(scanf("%s %s",str1,str2)!=EOF){
if(judge()) printf("Yes\n");
else printf("No\n");
}
return 0;
}
—— 生命的意义,在于赋予它意义。
分享到:
相关推荐
Algorithm-UVA-Solutions-in-Python.zip,python 3中各种uva(acm)问题的解决方案。,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
开源项目-codingsince1985-UVa#uva-online-judge-solutions-in-golang.zip,两年来每天都在解决一个uva在线裁判问题,算起来…
判断输入字符串是否为镜像或回文串。 来源于UVaOJ - 401. 水题。
uva705 Slash Maze 的代码,在UVaOJ上通过
PDF试题
uva532 Dungeon Master的源代码,并且AC了
这是UVA133 TheDoleQueue救济金发放问题,经典的算法问题。初学算法的人要对这种算法非常熟悉并且能熟练运用。
tpcw-nyu-uva-client 客户端
leetcode 2 算法-Java UVa Online Judge(ACM-ICPC Live ...使用:数组、哈希表、链表、二分搜索、动态规划、堆栈、堆、reedy、排序、树 DFS、BFS、图、二分搜索树、递归、记忆、队列、映射等。...Uva-ACM-ICPC