偷吃糖果
Time Limit: 1000Ms
Memory Limit: 65536KB
Description
小鱼喜欢吃糖果。他有两盒糖果,两盒糖果分别仅由小写字母组成的字符串s和字符串t构成。其中'a'到'z'表示具体的某种糖果类别。他原本打算送给他喜欢的女生,但是要送给女孩子的话两盒糖果不能有差别
(即字符串s和t完全相同)。所以,他决定偷吃几块,他吃糖果的策略是每次选出一盒糖果中两个连续的同种类别的糖果,然后吃掉其中一块。
该策略可以使用多次。例如一盒糖果是'rrrjj',他可以把这盒糖果变成'rrjj'或者'rrrj'。现在你要告诉小鱼,经过他多次偷吃糖果之后,两盒糖果能否送给他喜欢的女孩子。如果可以输出'Yes',如果不行输出'No'。
Input
第一行一个T,表示T组测试数据。每组测试数据格式如下。第一行表示字符串s,第二行表示字符串t。1 ≤ T ≤ 100Each character of s, t will be between 'a' and 'z'.1 ≤ length of string s ≤ 10001 ≤ length of string t ≤ 1000
Sample Input
2
rrrjj
rrrj
rj
jr
Sample Output
Yes
No
Hint
题目中的第一个样例:
第一盒糖果:rrrjj -> rrjj -> rjj -> rj
第二盒糖果:rrrj -> rrj -> rj
/*
思路:
把连续相同的缩成一个字母,然后对比一下即可
hhh-2016-04-17 13:01:22
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <math.h>
using namespace std;
#define lson (i<<1)
#define rson ((i<<1)|1)
typedef long long ll;
const int mod = 1000000009;
const int maxn = 1100;
char s1[maxn];
char s2[maxn];
char str1[maxn];
char str2[maxn];
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int tot1,tot2;
scanf("%s%s",s1,s2);
tot1 = tot2 = 0;
str1[tot1++] = s1[0];
for(int i=1; s1[i]!='\0'; i++)
{
if(s1[i]!=s1[i-1]) str1[tot1++]=s1[i];
}
tot2 = 0;
str2[tot2++] = s2[0];
for(int i=1; s2[i]!='\0'; i++)
{
if(s2[i]!=s2[i-1]) str2[tot2++]=s2[i];
}
if(tot1!=tot2) printf("No\n");
else
{
bool flag = true;
for(int i=0; i<tot1; i++)
{
if(str1[i]!=str2[i])
{
flag = false;
break;
}
}
if(flag) printf("Yes\n");
else printf("No\n");
}
}
return 0;
}
count_prime
Time Limit: 1000ms
Memory Limit: 65536KB