新生训练赛002补题

J - 新年快乐

Frog Wa has many frogs, so he can hear GuaGuaGua every day. But one day a flappy bird ate his frogs, so Frog Wa decided to build a fence to protect his precious frogs. Frog Wa told you four points (x, 0), (x, y), (z, 0), (z, t) which represent for the vertex of the fence. he want to know the area of the fence, can you tell him?

Input

The input consist of four integers x, y, z and t. 0 <= x, y, z, t <=
10000, x < z and y < t.

Output

For each test case, print the area, numbers should accurate to one
decimal places.

Sample Input

1 1 2 2
0 2 6 6
0 0 2 10

Sample Output

1.5
24.0
10.0

#include <stdio.h>
#include <math.h>
int main()
{
	int x,y,z,t;
	int c,k,i;
	for(i=0;i>=0;i++)
	{
	while(scanf("%d%d%d%d",&x,&y,&z,&t)!=EOF)
	{
		double area;
	area=((y+t)*(z-x))*1.0/2;
    printf("%.1f\n",area);
	}
	return 0;
	}
}

**

H - Perfect String

A string is called beautiful if no two consecutive characters are equal. For example, “ababcb”, “a” and “abab” are beautiful strings, while “aaaaaa”, “abaa” and “bb” are not.

扫描二维码关注公众号,回复: 8834632 查看本文章

Ahcl wants to construct a beautiful string. He has a string s, consisting of only characters ‘a’, ‘b’, ‘c’ and ‘?’. Ahcl needs to replace each character ‘?’ with one of the three characters ‘a’, ‘b’ or ‘c’, such that the resulting string is beautiful. Please help him!

More formally, after replacing all characters ‘?’, the condition si≠si+1 should be satisfied for all 1≤i≤|s|−1, where |s| is the length of the string s.

Input

The first line contains positive integer t (1≤t≤1000) — the number of
test cases. Next t lines contain the descriptions of test cases.

Each line contains a non-empty string s consisting of only characters
‘a’, ‘b’, ‘c’ and ‘?’.

It is guaranteed that in each test case a string s has at least one
character ‘?’. The sum of lengths of strings s in all test cases does
not exceed 105.

Output

For each test case given in the input print the answer in the following format:

If it is impossible to create a beautiful string, print “-1” (without
quotes); Otherwise, print the resulting beautiful string after
replacing all ‘?’ characters. If there are multiple answers, you can
print any of them.

Example
Input

3 a???cb
a??bbc
a?b?c

Output

ababcb
-1
acbac

Note

In the first test case, all possible correct answers are “ababcb”,
“abcacb”, “abcbcb”, “acabcb” and “acbacb”. The two answers “abcbab”
and “abaabc” are incorrect, because you can replace only ‘?’
characters and the resulting string must be beautiful.

In the second test case, it is impossible to create a beautiful
string, because the 4-th and 5-th characters will be always equal.

In the third test case, the only answer is “acbac”.

#include <stdio.h>
#include <string.h>
int main()
{
	int n,i,len,count=0;
	char s[1000000];
	scanf("%d",&n);
	while(n--)
	{
		count=0;
		scanf("%s",s);
		len=strlen(s);
		for(i=0;i<len;i++)
		{
			if((s[i]==s[i+1])&&(s[i]!='?'))
			{
			    count=1;
				break;
			}
			else if(s[i]=='?')
			{
				if(i==0)
				{
					if(s[1]!='a') 
					{
						s[0]='a';continue;
					}
					if(s[1]!='b') 
					{
						s[0]='b';continue;
					}
					if(s[1]!='c') 
					{
						s[0]='c';continue;
					}
				}
				if(i!=0)
				{
					if((s[i-1]!='a')&&(s[i+1]!='a'))
					{
						s[i]='a';continue;
					}
					if((s[i-1]!='b')&&(s[i+1]!='b'))
					{
						s[i]='b';continue;
					}
					if((s[i-1]!='c')&&(s[i+1]!='c'))
					{
						s[i]='c';continue;
					}
				}
			}
		}
		for(i=0;i<len;i++)
		if(s[i]==s[i+1])
		{
			count=1;
		    break;
		}
		if(count==0)
		printf("%s\n",s);
		else
		printf("-1\n");
	}
	return 0;
} 

G - 0011

Alex likes to play with one and zero!One day he gets an empty string.So our cute boy wants to add one and zero in it. Every time he will add ‘01’in the string at any position and then get a new string.For example:if the string is “01” now ,he can get “0101” or “0011,Now give you a string that is Alex has get,you need to answer whether the string is legal?

Input

First is a integer n(n<=100) Next contains n lines .Every line is a
string whose legth is no more than 1000.

Output

For each case output “YES” in a single line if it’s legal. Or you
need to output “NO”;

Sample Input

3
0101
0110
0011

Sample Output

YES
NO
YES

#include <stdio.h>
#include <string.h>
int main()
{
	int n,i,len,j,k,count=0,temp;
	int ydgs=0,ldgs=0;
	int bz=0;
	char s[1001];
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%s",&s);
		len=strlen(s);
		for(k=0;k<len;k++)
		{
			bz=0;
			if(s[k]=='0');
			{
				ydgs=ldgs=0;
				temp=k;
			for(j=0;j<k;j++)
			{
				if(s[j]=='1')
				ydgs++;
				else
				ldgs++;
			} 
				if(ydgs>ldgs)
			    {
		       	   printf("NO\n");
		       	   bz++;
			       break;
			    }
			}
	    }
	    if(!bz)
	    printf("YES\n");
	}
	return 0;
}
发布了4 篇原创文章 · 获赞 0 · 访问量 126

猜你喜欢

转载自blog.csdn.net/Legend_666/article/details/103907114
今日推荐