codeforces-723【B细节】

题目链接:点击打开链接

A. The New Year: Meeting Friends
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x1, the second friend lives at the pointx2, and the third friend lives at the point x3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?

It's guaranteed that the optimal answer is always integer.

Input

The first line of the input contains three distinct integers x1x2 and x3 (1 ≤ x1, x2, x3 ≤ 100) — the coordinates of the houses of the first, the second and the third friends respectively.

Output

Print one integer — the minimum total distance the friends need to travel in order to meet together.

Examples
input
7 1 4
output
6
input
30 20 10
output
20
Note

In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.



#include<cstdio>
#include<algorithm>
using namespace std;
int a,b,c;
int main()
{
	while(~scanf("%d %d %d",&a,&b,&c))
	{
		int mmin=min(a,min(b,c));
		int mmax=max(a,max(b,c));
		int sum=a+b+c;
		int mid=sum-mmin-mmax;
		printf("%d\n",mid-mmin+mmax-mid);
	}
	return 0;
}

题目链接:

B. Text Document Analysis
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters.

In this problem you should implement the similar functionality.

You are given a string which only consists of:

  • uppercase and lowercase English letters,
  • underscore symbols (they are used as separators),
  • parentheses (both opening and closing).

It is guaranteed that each opening parenthesis has a succeeding closing parenthesis. Similarly, each closing parentheses has a preceding opening parentheses matching it. For each pair of matching parentheses there are no other parenthesis between them. In other words, each parenthesis in the string belongs to a matching "opening-closing" pair, and such pairs can't be nested.

For example, the following string is valid: "_Hello_Vasya(and_Petya)__bye_(and_OK)".

Word is a maximal sequence of consecutive letters, i.e. such sequence that the first character to the left and the first character to the right of it is an underscore, a parenthesis, or it just does not exist. For example, the string above consists of seven words: "Hello", "Vasya", "and", "Petya", "bye", "and" and "OK". Write a program that finds:

  • the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses),
  • the number of words inside the parentheses (print 0, if there is no word inside the parentheses).
Input

The first line of the input contains a single integer n (1 ≤ n ≤ 255) — the length of the given string. The second line contains the string consisting of only lowercase and uppercase English letters, parentheses and underscore symbols.

Output

Print two space-separated integers:

  • the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses),
  • the number of words inside the parentheses (print 0, if there is no word inside the parentheses).
Examples
input
37
_Hello_Vasya(and_Petya)__bye_(and_OK)
output
5 4


input
37
_a_(_b___c)__de_f(g_)__h__i(j_k_l)m__
output
2 6


input
27
(LoooonG)__shOrt__(LoooonG)
output
5 2


input
5
(___)
output
0 0


Note

In the first sample, the words "Hello", "Vasya" and "bye" are outside any of the parentheses, and the words "and", "Petya", "and" and "OK" are inside. Note, that the word "and" is given twice and you should count it twice in the answer.

比赛的时候,一直说我 text6 是 WA 的,怎么想都没找到 bug,有一点没考虑到就是:如果串不是以一个符号结尾的,那么最后的时候还剩余一个单词的长度没有比较。当时这个题就 GG了

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n;
char str[300];
int main()
{
	while(~scanf("%d",&n))
	{
		scanf("%s",str);
		int len=strlen(str);
		int ans1=0,ans2=0,cnt=0;
		bool flag=0;
		for(int i=0;str[i];i++)
		{
			if((str[i]>='A'&&str[i]<='Z')||(str[i]>='a'&&str[i]<='z'))
			{
				cnt++;
			}
			else
			{
				if(!flag)
					ans1=max(ans1,cnt);
				if(flag&&cnt) // 这里判 cnt,是因为特殊符号连着的时候是不计的如 ‘(h__j) ’ 
				{
					ans2++;
				}
				if(str[i]=='(')
				{
					flag=1;
				}
				if(str[i]==')')
				{
					flag=0;
				}
				cnt=0;
			}
		}
		// 这里串可能不是以符号结尾的(也就是剩余最后一个单词的长度没比较),所以 cnt可能不为 0,故多加一层筛选
		printf("%d %d\n",max(ans1,cnt),ans2); 
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值