2021.01.09哈学院20的5道题

Rabbit loves flowers very much and she plants n pots of flowers in her house. But she never prunes them because she is lazy. So the flowers have different heights and look ugly. One day, Kayaking decides to prune the flowers to make them look beautiful. To make them have equal heights, smart Kayaking has a wonderful idea. Initially, the i-th pot of flower’s height is a[i]. Each time, Kayaking will select n-1 pots of flowers and prune them to make their height subtract 1 with his 49m knife. Exactly, the height of the flowers is at least 1. Now, Kayaking wants to know if it is possible to prune the flowers to make them have equal height. If possible, what is the minimum times he prunes the flowers. Could you tell him?
Input
The input starts with a line contains exactly one positive number T which is the number of test case.
Each test case starts with a line contains a number n indicates the number of flowers. Then there is a line contains n numbers indicates a[i].
Output
For each test case, print a single line containing one integer—the minimum times Kayaking prunes the flowers, or -1 if it is impossible.
Sample Input
2
5
1 2 2 2 2
5
1 2 2 2 3
Sample Output
1
-1

Hint
T<=10,n<=105,ai<=109

    ```

#include
#include
#include
#include
using namespace std;
typedef long long ll;
int main()
{
int t;
scanf("%d",&t);
while(t–)
{
ll n;
scanf("%lld",&n);
int i;
ll a[100010];
for(i=0;i<n;i++)
{
scanf("%lld",&a[i]);
}
sort(a,a+n);
ll sum=0;
for(i=0;i<n;i++)
{
sum+=(a[n-1]-a[i]);
}
if(a[n-1]-sum<1)
printf("-1\n");
else
printf("%lld\n",sum);
}
return 0;
}

  
Larry graduated this year and finally has a job. He's making a lot of money, but somehow never seems to have enough. Larry has decided that he needs to grab hold of his financial portfolio and solve his financing problems. The first step is to figure out what's been going on with his money. Larry has his bank account statements and wants to see how much money he has. Help Larry by writing a program to take his closing balance from each of the past twelve months and calculate his average account balance.
Input
The input will be twelve lines. Each line will contain the closing balance of his bank account for a particular month. Each number will be positive and displayed to the penny. No dollar sign will be included.
Output
The output will be a single number, the average (mean) of the closing balances for the twelve months. It will be rounded to the nearest penny, preceded immediately by a dollar sign, and followed by the end-of-line. There will be no other spaces or characters in the output.
Sample Input
100.00
489.12
12454.12
1234.10
823.05
109.20
5.27
1542.25
839.18
83.99
1295.01
1.75
Sample Output
$1581.42      

#include<stdio.h>
int main()
{
double w[20],count=0;
int i;
for(i=1;i<=12;i++)
{
scanf("%lf",&w[i]);
count=count+w[i];
}
printf("$%.2lf",count/12);
return 0;
}


给出3个正整数A B C,求A^B Mod C。
例如,3 5 8,3^5 Mod 8 = 3。
Input
3个正整数A B C,中间用空格分隔。(1 <= A,B,C <= 10^9)
Output
输出计算结果
Sample Input
3 5 8
Sample Output
3

#include<stdio.h>
int no(long long a,long long b,long long c)
{
int ans=1;
a=a%c;
while(b>0)
{
if(b%2==1)
ans=ansa%c;
a=a
a%c;
b=b/2;
}
return ans;
}
int main()
{
long long a,b,c;
scanf("%lld%lld%lld",&a,&b,&c);
a=no(a,b,c);
printf("%lld\n",a);
return 0;
}


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.

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.

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.

Examples
Input
8
Output
YES
Note
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 

#include
using namespace std;
int main()
{
int a;
cin >> a;
if (a % 2 == 0&&a>=4)
cout << “YES”;
else cout << “NO”;
}



Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.

Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.

This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.

Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".

You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.

Input
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.

Output
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.

Examples
Input
4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis
Output
word
l10n
i18n
p43s

#include<stdio.h>
#include<string.h>
int main()
{
int n,len,k;
char w[100];
scanf("%d",&n);
int i;
for(i=0;i<n;i++)
{
scanf("%s",w);
getchar();
len=strlen(w);
k=len;
if(len<10)
{
puts(w);

	}
	else{
		printf("%c%d%c\n",w[0],k-2,w[len-1]);
	}
}
return 0;

}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值