2020年1月23日山师比赛题解

G - 【The__Flash】的水题

You are given two strings of equal length s and t consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.

During each operation you choose two adjacent characters in any string and assign the value of the first character to the value of the second or vice versa.

For example, if s is “acbc” you can get the following strings in one operation:

“aabc” (if you perform s2=s1);
“ccbc” (if you perform s1=s2);
“accc” (if you perform s3=s2 or s3=s4);
“abbc” (if you perform s2=s3);
“acbb” (if you perform s4=s3);
Note that you can also apply this operation to the string t.

Please determine whether it is possible to transform s into t, applying the operation above any number of times.

Note that you have to answer q independent queries.

Input

The first line contains one integer q (1≤q≤100) — the number of
queries. Each query is represented by two consecutive lines.

The first line of each query contains the string s (1≤|s|≤100)
consisting of lowercase Latin letters.

The second line of each query contains the string t (1≤|t|≤100,
|t|=|s|) consisting of lowercase Latin letters.

Output

For each query, print “YES” if it is possible to make s equal to t,
and “NO” otherwise.

You may print every letter in any case you want (so, for example, the
strings “yEs”, “yes”, “Yes”, and “YES” will all be recognized as
positive answer).

Example
Input

3
xabb
aabx
technocup
technocup
a
z

Output

YES
YES
NO

Note

In the first query, you can perform two operations s1=s2 (after it s
turns into “aabb”) and t4=t3 (after it t turns into “aabb”).

In the second query, the strings are equal initially, so the answer is “YES”.

In the third query, you can not make strings s and t equal. Therefore,the answer is “NO”.

题意:给定两个字符串s和t,长度相同,如果s字符串能转换成t字符串,输出YES,否则输出NO
解题思路:从t字符串的第一个字符开始寻找,如果一旦在s字符串中发现t中的字符,以count为标志,count++来确定是否符合条件。

#include <stdio.h>
#include <string.h>
int main()
{
	int n,i,k,len1,len2;
	char s[1000],t[1000];
	scanf("%d",&n);
	while(n--)
	{
		int count=0;
		scanf("%s",s);len1=strlen(s);
	    scanf("%s",t);len2=strlen(t);
	    for(k=0;k<len2;k++)
      {
		for(i=0;i<len1;i++)
		{
			if(t[k]==s[i])
			{
				count++;
			    break;
			}
		}
	  }
	  if(count)
	  printf("YES\n");
	  else
	  printf("NO\n");
	}
	return 0;
}

**

J - 【The__Flash】的球球

N个气球排成一排,从左到右依次编号为1,2,3…N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?

Input

每个测试实例第一行为一个整数N,(N <= 100000).接下来的N行,每行包括2个整数a b(1 <= a <= b <= N)。 当N = 0,输入结束。

Output

每个测试实例输出一行,包括N个整数,第I个数代表第I个气球总共被涂色的次数。

**
Sample Input

3

1 1

2 2

3 3

3

1 1

1 2

1 3

0

Sample Output

1 1 1

3 2 1

【注】 如果按照正常的for循环,然后累加值,容易溢出。

#include <stdio.h>
#include <string.h>
int main()
{
	int N,a[101000];
	int i,k,x,y,w;
	while(scanf("%d",&N)!=EOF&&N!=0)
	{
		memset(a,0,sizeof(a));
		for(i=1;i<=N;i++)
		{
			scanf("%d%d",&x,&y);
			a[x]++;//前缀和
            a[++y]--;//前缀和
		}
		for(i=1;i<=N;i++)
		{
			a[i]=a[i-1]+a[i];//前缀和 
			printf("%d ",a[i]);
		}
		printf("\n");
	}
	return 0;
}
发布了4 篇原创文章 · 获赞 0 · 访问量 100

猜你喜欢

转载自blog.csdn.net/Legend_666/article/details/104081137