码迷,mamicode.com
首页 > 其他好文 > 详细

8月1号水题走一波

时间:2018-08-02 22:53:56      阅读:336      评论:0      收藏:0      [点我收藏+]

标签:print   one   dal   nsis   4.4   tween   clu   begin   sam   

A. Generate Login

The preferred way to generate user login in Polygon is to concatenate a prefix of the user‘s first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.

You are given the first and the last name of a user. Return the alphabetically(字母顺序地) earliest login they can get (regardless of other potential Polygon users).

As a reminder, a prefix(前缀) of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and ‘bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac".

Input

The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive.

Output

Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well.

Examples
input
harry potter
output
hap
input
tom riddle
output
tomr
 

 

题目意思:给你用户的名和姓,让你生成一个按字母顺序的最短登录名,原则是:名(也就是a串)和姓(也就是b串)都要保留第一个字母,a串除了第一的字母之后的要取到字典序不大于b串第一个字母位置。

说起来还是很繁琐,其实这个有点生活气息,我们平时上网也有这样处理用户名字的,当时我是第二个出这道题的,多少是有点猜的,不过猜对了。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 char a[100],b[100];
 6 char c[100];
 7 int main()
 8 {
 9     int i,lena,lenb,counts;
10     scanf("%s",&a);
11     scanf("%s",&b);
12     counts=1;
13     lena=strlen(a);
14     lenb=strlen(b);
15     for(i=1;i<lena;i++)
16     {
17         if(a[i]<b[0])
18         {
19             counts++;
20         }
21         else
22         {
23             break;
24         }
25     }
26     for(i=0;i<counts;i++)
27     {
28         c[i]=a[i];
29     }
30     c[i]=b[0];
31     i++;
32     c[i]=\n;
33     printf("%s",c);
34     return 0;
35 }

 

 

Boxes Packing

Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.

Mishka can put a box i into another box j if the following conditions are met:

  • i-th box is not put into another box;
  • j-th box doesn‘t contain any other boxes;
  • box i is smaller than box j (ai < aj).

Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.

Help Mishka to determine the minimum possible number of visible boxes!

Input

The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.

Output

Print the minimum possible number of visible boxes.

Examples
Input
3
1 2 3
Output
1
Input
Copy
4
4 2 4 3
Output
2
Note

In the first example it is possible to put box 1 into box 2, and 2 into 3.

In the second example Mishka can put box 2 into box 3, and box 4 into box 1.

 

题目意思:套盒子,尺寸大的盒子能装下尺寸小的盒子,给你一些盒子,问你最后最少能剩下多少的盒子。

解题思路:这个题有点俄罗斯套娃的意思,大的能装下小的,那么我们只需要看看最后剩下尺寸最大的盒子的个数就行了。

 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int a[5010];
 6 int main()
 7 {
 8     int n,counts,maxs,i;
 9     scanf("%d",&n);
10     for(i=0; i<n; i++)
11     {
12         scanf("%d",&a[i]);
13     }
14     sort(a,a+n);
15     counts=1;
16     maxs=1;
17     for(i=1; i<n; i++)
18     {
19         if(a[i]==a[i-1])
20         {
21             counts++;
22             if(maxs<counts)
23             {
24                 maxs=counts;
25             }
26         }
27         else
28         {
29             counts=1;
30         }
31     }
32     printf("%d\n",maxs);
33     return 0;
34 }

 

这里再给出使用map这一容器的做法:

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<map>
 5 using namespace std;
 6 int main()
 7 {
 8     int n,maxs,i,num;
 9     maxs=-1;
10     map<int,int>mp;
11     scanf("%d",&n);
12     for(i=0; i<n; i++)
13     {
14         scanf("%d",&num);
15         mp[num]++;
16         maxs=max(maxs,mp[num]);
17     }
18     printf("%d\n",maxs);
19     return 0;
20 }

 

 

 

8月1号水题走一波

标签:print   one   dal   nsis   4.4   tween   clu   begin   sam   

原文地址:https://www.cnblogs.com/wkfvawl/p/9409730.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!