当前位置: 代码迷 >> C语言 >> [讨论]第四期题目,大家做做.
  详细解决方案

[讨论]第四期题目,大家做做.

热度:370   发布时间:2006-12-03 20:09:08.0
[讨论]第四期题目,大家做做.

All in All

--------------------------------------------------------------------------------

Time limit: 1 Seconds Memory limit: 32768K
Total Submit: 2329 Accepted Submit: 763

--------------------------------------------------------------------------------
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 strings s and t, you have to decide whether s is a subsequence of t, i.e. if you can remove characters from t such that the concatenation of the remaining characters is s.


Input

The input contains several testcases. Each is specified by two strings s, t of alphanumeric ASCII characters separated by whitespace. Input is terminated by EOF.


Output

For each test case output, print "Yes" if s is a subsequence of t or "No" if not.


Sample Input

sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter


Sample Output

Yes
No
Yes
No

/*英语好的帮忙翻译一下,谢了*/

搜索更多相关的解决方案: 题目  讨论  

----------------解决方案--------------------------------------------------------

Ones

--------------------------------------------------------------------------------

Time limit: 1 Seconds Memory limit: 32768K
Total Submit: 1799 Accepted Submit: 854

--------------------------------------------------------------------------------

Given any integer 0 <= n <= 10000 not divisible by 2 or 5, some multiple of n is a number which in decimal notation is a sequence of 1's. How many digits are in the smallest such a multiple of n?


Sample Input

3
7
9901


Sample Output

3
6
12

/*给出一个不能被2和5整除的数,问这个数可以被最少的几个1组成的数整除*/


----------------解决方案--------------------------------------------------------

第二题:

#include <stdio.h>

int main()
{
int n, count;

while (EOF != scanf("%d", &n))
{
int t = 0;

count = 0;
while ((t * 10 + 1) % n != 0)
{
count++;
t = (t * 10 + 1) % n;
}
count++;
printf("%d\n", count);
}

return 0;
}


----------------解决方案--------------------------------------------------------
我的第二题解法:从1开始,对输入数据%运算,如果不能整除则1*10+1,(11*10+1;111*10+1...)然后继续,直到成功输出结果

[此贴子已经被作者于2006-12-3 20:36:05编辑过]



----------------解决方案--------------------------------------------------------
以下是引用卧龙孔明在2006-12-3 20:33:39的发言:
我的第二题解法:从1开始,对输入数据%运算,如果不能整除则1*10+1,(11*10+1;111*10+1...)然后继续,直到成功输出结果

对于9901, 是12个1,long的范围好象不够啊
----------------解决方案--------------------------------------------------------

以下是引用我不是郭靖在2006-12-3 20:39:48的发言:

对于9901, 是12个1,long的范围好象不够啊

用long long或高精度运算(数组)


----------------解决方案--------------------------------------------------------
对于9981,需要9972个1,用高精度可能很烦
----------------解决方案--------------------------------------------------------
我不是郭靖斑竹的算法是正确的.
不需要设置很高的存储类型.

----------------解决方案--------------------------------------------------------

第一题

#include <stdio.h>
#define N 100000

int main()
{
char s[N], t[N];
int i, index;

while (EOF != scanf("%s%s", s, t))
{
index = 0;
for (i = 0; t[i] != '\0'; i++)
{
if (s[index] == t[i])
{
index++;
if (s[index] == '\0')
{
printf("Yes\n");
break;
}
}
}
if (t[i] == '\0')
printf("No\n");
}

return 0;
}


----------------解决方案--------------------------------------------------------

NO. 1

程序代码:

#include<stdio.h>
#include<string.h>
#define N 20

void main()
{
int count=0,k=0,flag=0;
char s[N],t[N];
while (printf(\"input two strings:\"),EOF != scanf(\"%s%s\", s, t))

{
for(int i=0;s[i]!='\0';i++)
{
for(int j=k;t[j]!='\0';j++)
{
if(s[i]==t[j])
{
flag=1;
count++;
k=j;
break;
}
}
if(flag==0) break;
}
printf(\"%s\n\",count==strlen(s)?\"YES\":\"NO\");
}
}

[此贴子已经被作者于2006-12-3 22:00:48编辑过]


----------------解决方案--------------------------------------------------------
  相关解决方案