练习赛22——题解

 

A - 1

One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.

一个炎热的夏天,皮特和他的朋友比利决定买一个西瓜。他们选择了最大和最成熟的,在他们看来。西瓜是称重后,天平显示w公斤。他们冲回家,渴得要死,决定分西瓜,但是他们面临一个困难的问题。

Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.

皮特和比利是偶数的狂热粉丝,这就是为什么他们要把西瓜分成两部分甚至体重公斤数要为偶数,同时它不是强制性的两部分是相等的。男孩们非常累,想尽快开始吃西瓜,这就是你应该帮助他们和解决的原因,如果他们能把西瓜用这种方式分开。当然,每个人都应该得到一个好的一部分重量。

Input

The first (and the only) input line contains integer number w (1 ≤ w ≤ 100) — the weight of the watermelon bought by the boys. 

第一行包含一个整数 n (1 <= n <= 100),代表男孩们的西瓜的重量。

Output

Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. 

如果期望的切法存在,输出YES;否则输出NO。

Example

Input
8

Output
YES

Note

在样例中,男孩们可以把西瓜切成重量分别为 4 和 4 的两块,或者把西瓜切成重量分别为 2 和 6 的两块。

思路:

 这是简单的奇偶数的加减问题,首先判断西瓜总数是否为偶数,因为偶+偶为偶,所以这一步可以筛掉一些案例,再去判断该数是否能分解成两个偶数即可。

 代码:

#include<stdio.h>

int main(void) {
	int n;//西瓜总重
	scanf("%d", &n);
	if (n % 2 == 0) {//判断是否为偶数
		for (int i = 2; i < n; i++) {
			if ((n - i) % 2 == 0 && i % 2 == 0) {//能分解成两个偶数的立即输出yes,结束程序
				printf("YES\n");
				return 0;
			}
		}
	}
		printf("NO\n");
	 

	return 0;
}

 

 

 B - 2

XUPT_ACM的杨队是一个强迫症晚期的大神,他特别反感长单词,就像 "localization" 和"internationalization" 。

于是睿智的杨队想出了一个方法来节约写单词的时间, 如果单词的长度严格大于10个字符,那么他可以用以下方法表示:

写下这个单词的第一个字母与最后一个字母,在它们之间写下除去第一个字母和最后一个字母后该单词包含的字母个数,这个数字是不包含前导零的十进制数字。

举个栗子, "localization" 可以表示为"l10n", "internationalization"可以被表示为"i18n".

你的任务是通过编写代码实现这样一个转化的过程,太长的单词通过上述方法表示,其他的单词保持不变

Input

第一行包含一个整数n (1 ≤ n ≤ 100). 接下来n行每行包含一个单词. 所有的单词由小写字母组成,单词的长度为1 到100个字符.

Output

输出 n 行. 第 i 行包括第 i 个单词的转化结果.

Examples

Input

4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis

Output

word
l10n
i18n
p43s

 思路:

这道题就是运用到string的统计字符长度,先是统计各个单词的长度,将符合10字符以上的按照题目要求输出,这里可以直接根据字符串存储的规律完成,知道字符长度,就可以知道前后两个字符,中间的数字只需用长度减去2即可,不符合的照常输出。在这里我是直接输入的时候就判断输出了,只用了一个for循环。

 代码:

#include<stdio.h>
#include<string.h>

int main(void) {
	char a[100][100];
	int n,len=0;

	scanf("%d", &n);//单词个数
	for (int i = 0; i < n; i++) {//输入单词并进行判断
		scanf("%s", &a[i]);
		len = strlen(a[i]);//判断单词长度
		if (len <= 10) {
			printf("%s\n", &a[i]);
		}
		else {
			printf("%c%d%c\n", a[i][0], len - 2, a[i][len - 1]);//根据字符串的长度,依次输出首字母,除首尾字符的长度,尾字母
		}
	}
	
	return 0;
}

 

 

 G - 7

Given two integers, a and b, you should check whether a is divisible by b or not. We know that an integer a is divisible by an integer b if and only if there exists an integer c such that a = b * c.

给定两个整数,a和b,您应该检查是否a整除b。我们知道,a整数整除的整数b当且仅当存在一个整数c, a = b * c。

Input

Input starts with an integer T (≤ 525), denoting the number of test cases.

输入从一个整数T(≤525),表示测试用例的数量。

Each case starts with a line containing two integers a (-10200 ≤ a ≤ 10200) and b (|b| > 0, b fits into a 32 bit signed integer). Numbers will not contain leading zeroes.

每个案例始于一行包含两个整数(-10200≤≤10200)和b (| | b > 0, b适用于32位有符号整型)。数字不包含前导零。

Output

For each case, print the case number first. Then print 'divisible' if a is divisible by b. Otherwise print 'not divisible'.

对于每个案例,先打印数量。然后打印“divisible”如果a是b整除。否则打印“not divisible”。

Sample Input

6
101 101
0 67
-101 101
7678123668327637674887634 101
11010000000000000000 256
-202202202202000202202202 -101

Sample Output

Case 1: divisible
Case 2: divisible
Case 3: divisible
Case 4: not divisible
Case 5: divisible
Case 6: divisible

 思路:

这个题目所给的数目很大,直接整除是无法完成的,所以需要转化成更简单的方式一步步完成,例如像写竖式一样,如下图,从前往后,除不尽的余数乘10后加上下一位继续除b,直到除到最后一位,若余数最后成为0,则a能整除b,反之则不能。前提是要先将a,b,化为正整数,方便运算。

 代码:

#include<stdio.h>
#include<string.h>
#include<math.h>

int main(void) {
	//因为该题的数很大,所以用上字符数组和longlong去存
	int n;
	char a[10000000];
	long long b;

	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {//一行行去判断
		long long x = 0;
		scanf("%s %lld", a, &b);
		b = abs(b);//将b转换为正数
		int l = strlen(a);//统计a的长度,方便下面按位去除
		for (int j = 0; j < l; j++) {
			if (a[j] == '-')//忽略掉a前面的负号
				continue;
			x = (x * 10 + a[j] - '0') % b;//从前往后对b进行整除求余
		}
		if (x == 0) {//若最后的余数为0,则a能整除b
			printf("Case %d: divisible\n", i);
		}
		else {//反之则不能
			printf("Case %d: not divisible\n", i);
		}
	}

	return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值