2021.1.4寒假打卡Day1

寒假打卡Day1

(说是说Day1,其实是Day2补写的(/ω\))
总之今天很水,划了一天的水。。。

problem 1: Way Too Long Words🔗

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

既然今天是来划水的,那题目水一点也正常是吧
读题找出关键点:
1.length is strictly more than 10 characters
2.write down the first and the last letter of a word
3.between them we write the number of letters between the first and the last letters

于是代码很简单就能想到了:

#include<iostream>
#include<cstring>
using namespace std;

int main(){
	char ch[105];
	int t;
	cin>>t;
	while(t--){
		cin>>ch;
		if(strlen(ch)<=10){
			cout<<ch<<endl;
			continue;
		}
		cout<<ch[0]<<strlen(ch)-2<<ch[strlen(ch)-1]<<endl;
	}
	return 0;
} 

problem 2 : Team🔗

One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won’t write the problem’s solution.

This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.

Input
The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem’s solution, otherwise he isn’t sure. The second number shows Vasya’s view on the solution, the third number shows Tonya’s view. The numbers on the lines are separated by spaces.

Output
Print a single integer — the number of problems the friends will implement on the contest.

Examples
input1

3
1 1 0
1 1 1
1 0 0

output1

2

input2

2
1 0 0
0 1 1

output2

1

Note
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn’t enough, so the friends won’t take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.

题目关键点:if at least two of them are sure about the solution
题目对于组员是否确定的表示方法方便了我们判定题目能否解出,和大于等于2即可

以下为代码:

#include<iostream>
using namespace std;

int main(){
	int t,a,b,c,ans=0;
	cin>>t;
	while(t--){
		cin>>a>>b>>c;
		if((a+b+c)>=2)++ans;
	}
	cout<<ans;
	return 0;
}

是不是很水

problem 3 : 道路🔗

Description

栗酱想要出去旅游。她选择了n个不同的城市,计划旅游的顺序是这样的:从第一个城市到第二个城市,然后是第三个第四个⋯⋯一直到第n个城市,然后再从第n个城市回到第n-1个,第n-2个,第n-3个⋯⋯一直到回到第一个城市。

但是每两个城市之间,有很多很多道路,不同的路有不同的长度。

栗酱不希望在一条路上走两遍(因为她想看到更多的风景),但她也想走最少的旅程。

数据保证两个相邻的城市之间至少有两条道路。

请输出最短的总旅行长度。

Input
数据的第一行是数据组数 T。在每组数据中:第一行是一个整数 n,代表有 n 个城市在栗酱的计划中。接下来的第 i 行中,先给出一个整数 ki ,表示从第 i 个城市到第 i+1 个城市之间有 ki 条路。紧接着给出 ki 个整数a1,a2,a3,······,a(ki)——第i条路的距离。
约定:

  • T≤100
  • n ,ki≤1000
  • 1≤ai ≤10000

Output
每组数据一行,直接输出答案。

Sample Input

1
5
2 1 5
2 10 15
3 4 6 7
7 98 45 12 32 45 21 54

Sample Output

74

反正按题意,就是把每两个城市间的最短两条路加进总和就行

以下代码:

#include<iostream>
using namespace std;

int main(){
	int ans=0,t,n,k,a=0,b=0,c=0;
	cin>>t;
	while(t--){
		ans=0;
		cin>>n;
		for(int i=1;i<n;i++){
			cin>>k;
			cin>>a>>b;
			if(k>2){
				for(int j=k;j>2;j--){
					cin>>c;
					if(c<a){
						a+=c;
						c=a-c;
						a-=c;
					}
					else if(c<b){
						b+=c;
						c=b-c;
						b-=c;
					}
				}
			}
			ans+=a+b;	
		}	
	}
	cout<<ans;
	return 0;
} 

就这样,划水的第一天就过去了(/ω\)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值