目录
简介
过年啦过年啦!!!(^0^),祝大家新年快乐,万事如意!!!!
接着奏乐接着打卡!\(^0^)/
A.Word Capitalization
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
大写是指在书写单词时,将其首字母大写。您的任务是将给出的单词大写。
注意,在大写过程中,除第一个字母外,其他字母保持不变。
Input
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
单行包含一个非空单词。该单词由小写和大写英文字母组成。单词长度不超过 103 。
Output
Output the given word after capitalization.
输出大写后的给定单词。
Examples
input
ApPLe
output
ApPLe
input
konjac
output
Konjac
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
string s;
int main()
{
cin>>s;
if(s[0]>=97&&s[0]<=122)
s[0]=toupper(s[0]);
cout<<s;
return 0;
}
哎嘿,不知道大家看到这道题会不会有一种熟悉感,好像和之前的Petya and Strings沾点边呢(当然也只是沾了个边哈哈传送门练习打卡(C++)-CSDN博客),这里再提一嘴toupper()函数和tolower()函数。
toupper():将小写字母转换为大写字母。
tolower():将大写字母转换为小写字母。
当然当然,我感觉直接减去32写起来比较简单。
#include<iostream>
#include<string>
using namespace std;
string s;
int main()
{
cin>>s;
if(s[0]>=97&&s[0]<=122)
s[0]-=32;
cout<<s;
return 0;
}
/*注意:值得注意的是toupper()和tolower()它们俩返回值都是int类型喔,也可以转换成char类型。另外cctype头文件和cwctype头文件是类似的,cctype
头文件用于处理ASCII字符,如isupper()
、tolower()
和isalpha()
等;cwctype
头文件则用于处理宽字符,如iswupper()
、towupper()
等。*/
isalnum | 检查字符是否为字母或数字 |
isalpha | 检查字符是否为字母 |
islower | 检查字符是否为小写 |
isupper | 检查字符是否为大写字符 |
isdigit | 检查字符是否为数字 |
isxdigit | 检查字符是为十六进制字符 |
isspace | 检查字符是否为空白间隔字符 |
tolower | 转换字符为小写 |
toupper | 转换字符为大写 |
iswalnum | 检查宽字符是否为字母数字 |
iswalpha | 检查宽字符是否为字母 |
iswlower | 检查宽字符是否为小写 |
iswupper | 检查宽字符是否为大写 |
iswdigit | 检查宽字符是否为数字 |
iswxdigit | 检查宽字符是否为十六进制字符 |
iswspace | 检查宽字符是否为空白间隔字符 |
towlower | 转换宽字符为小写 |
towupper | 转换宽字符为大写 |
towctrans | 按照指定的 LC_TYPE 映射类别进行字符映射 |
wctrans | 在当前 C 本地环境中查找字符映射类别 |
具体的有兴趣自行了解喔^0^(差点以为之前的搞错了嘞)。
A. Boy or Girl
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names.
This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.
如今,许多男生在论坛上使用漂亮女孩的照片作为头像。所以很难一眼看出用户的性别。去年,我们的主人公去了一个论坛,和一位美女聊得很开心(他是这么认为的)。从那以后,他们经常聊天,并最终成为网络情侣。
但昨天,他在现实世界中见到了 "她",发现 "她 "其实是一个非常强壮的男人!我们的主人公很伤心,他现在太累了,无法再爱了。于是,他想出了一个通过用户名识别用户性别的方法。
这就是他的方法:如果一个人的用户名中不同字符的个数是奇数,那么他就是男性,否则她就是女性。给你一个表示用户名的字符串,请帮助我们的主人公用他的方法确定这个用户的性别。
Input
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
第一行包含一个非空字符串,其中只包含小写英文字母--用户名。该字符串最多包含 100 个字母。
Output
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
如果按照我们主人公的方法是女性,则打印 "与她聊天!"(不带引号),否则打印 "忽略他!"(不带引号)。
Examples
input
wjmzbmr
output
CHAT WITH HER!
input
xiaodao
output
IGNORE HIM!
input
sevenkplus
output
CHAT WITH HER!
Note
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH
第一个例子。wjmzbmr "中有 6 个不同的字符。这些字符是w"、"j"、"m"、"z"、"b"、"r"。因此,wjmzbmr 是一位女性,您应该打印 "与她聊天!"。
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int ans=0;
string s;
int main()
{
cin>>s;
sort(s.begin(),s.end());
for(int i=0;i<s.length();i++){
if(s[i]!=s[i+1])
ans++;
}
if(ans%2==0)
cout<<"CHAT WITH HER!";
else cout<<"IGNORE HIM!";
return 0;
}
又是一道很明显的水题~~~不过得认真读题哇(-_-)一开始我还以为是相同的字母为偶数则对方是女生呢,其实是不相同的字母数。
我的思路很简单!先对字母排序,这样相同的字母就会挨着了,直接判断+计数统计一下下就行啦。当然,我相信大家还有很多简单的方法的,欢迎讨论呀(^0^)。
A. Stones on the Table
There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
桌子上有 n 块石头,每块石头都可以是红色、绿色或蓝色。请计算最少要从桌子上拿走多少颗棋子,才能使相邻的两颗棋子具有不同的颜色。如果一排石子之间没有其他石子,则视为相邻石子。
Input
The first line contains integer n (1 ≤ n ≤ 50) — the number of stones on the table.
The next line contains string s, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to n from left to right. Then the i-th character s equals "R", if the i-th stone is red, "G", if it's green and "B", if it's blue.
第一行包含整数 n (1 ≤ n ≤ 50) 。 (1 ≤ n ≤ 50) - 桌面上的棋子数量。
下一行包含字符串 s ,表示棋子的颜色。我们将考虑从左到右编号为 1 至 n 的一行中的棋子。如果第 i 个字符 s 中的第 i 块棋子是红色的,那么它就等于"R";如果是绿色的,那么它就等于"G";如果是蓝色的,那么它就等于"B"。
Output
Print a single integer — the answer to the problem.
打印一个整数--问题的答案。
#include<iostream>
#include<string>
using namespace std;
int ans=0,l;
string s;
int main()
{
cin>>l>>s;
for(int i=0;i<l;i++){
if(s[i]==s[i+1])
ans++;
}
cout<<ans;
return 0;
}
哎嘿,看到做个代码有没有一种熟悉感?
(因为就是上一题裁剪下来的啦^-^超水的一道题呢)
这道题我们直接按照顺序比较就好啦,遇到和上一个字母一样的直接把它丢出去!
A. Bear and Big Brother
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.
After how many full years will Limak become strictly larger (strictly heavier) than Bob?
小熊利马克想成为最大的熊,至少要比他的兄弟鲍勃大。
现在,利马克和鲍勃的体重分别是 a 和 b 。可以保证的是,利马克的体重小于或等于他哥哥的体重。
利马克吃得很多,他的体重每年都会增加三倍,而鲍勃的体重每年都会增加一倍。
经过多少年后,Limak 的体重将严格大于(严格重于)Bob 的体重?
Input
The only line of the input contains two integers a and b (1 ≤ a ≤ b ≤ 10) — the weight of Limak and the weight of Bob respectively.
输入的唯一一行包含两个整数 a 和 b ( 1 ≤ a ≤ b ≤ 10 ) --分别是 Limak 的权重和 Bob 的权重。
Output
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
打印一个整数,表示 Limak 严格大于 Bob 的整数年数。
Examples
input
4 7
output
2
input
4 9
output
3
input
1 1
output
1
Note
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.
In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.
In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.
在第一个样本中,Limak 初始体重为 4 ,Bob 初始体重为 7 。一年后,他们的体重分别为 4·3 = 12 和 7·2 = 14 (一个体重增加了三倍,另一个增加了一倍)。Limak 还没有比 Bob 大。第二年后,权重分别为 36 和 28 ,因此第一个权重大于第二个权重。Limak 在两年后变得比 Bob 大,所以应该打印 2 。
在第二个样本中,Limak 和 Bob 接下来几年的权重分别为 12 和 18 : 12 和 18 ,然后是 36 和 36 ,最后是 108 和 72 (三年后)。答案是 3 。请记住,利马克希望自己的权重大于鲍勃,他不会满足于权重相等。
在第三个样本中,Limak 在第一年后变得比 Bob 大。这时他们的权重分别为 3 和 2 。
#include<iostream>
using namespace std;
int a,b,years=0;
int main()
{
cin>>a>>b;
while(a<=b){
years++;
a*=3,b*=2;
}
cout<<years;
return 0;
}
嘿嘿秒了秒了,还是得注意读题呀,我第一次又是因为读错题Wrong answer了。
总之,我们在一开始判断a是否已经大于b就行啦,没有的话就加一年然后a便成以前的3倍,b变成2倍就行咯~
A. Elephant
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.
一头大象决定去拜访它的朋友。原来,大象的房子位于坐标线的 0 点,而它朋友的房子位于坐标线的 x(x > 0) 点。大象可以向前移动 1 、 2 、 3 、 4 或 5 个位置。请计算大象最少需要走多少步才能到达朋友家。
Input
The first line of the input contains an integer x (1 ≤ x ≤ 1 000 000) — The coordinate of the friend's house.
输入的第一行包含一个整数 x ( 1 ≤ x ≤ 1 000 000 ) - 朋友家的坐标。
Output
Print the minimum number of steps that elephant needs to make to get from point 0 to point x.
打印大象从点 0 到点 x 所需的最少步数。
Examples
input
5
output
1
input
12
output
3
Note
In the first sample the elephant needs to make one step of length 5 to reach the point x.
In the second sample the elephant can get to point x if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach x in less than three moves.
在第一个示例中,大象需要迈出长度为 5 的一步才能到达点 x 。
在第二个示例中,如果大象走 3 、 5 和 4 步,就能到达点 x 。还有其他方法可以得到最佳答案,但是大象不能在三步以内到达 x 。
#include<iostream>
using namespace std;
long long x,k;
int main()
{
cin>>x;
k=x/5;
if(x%5!=0)
k++;
cout<<k;
return 0;
}
大象可以走1、2、3、4、5步,咱们要求最小的步数就可以先走完5可以走完的,5没法走的路程交由1、2、3、4任何一个都可以走到目的地,所以我们可以直接先将距离x整除5得到步数k,如果还有剩余的路程没走(也就是x%5!=0),k再加一就是最后的答案咯\(^-^)/。
感觉这道题使用BFS应该也是可行的,不过对于这道题来讲用BFS就有点子麻烦啦。
今天就先到这儿啦,嘿咻嘿咻,大家新年快乐!!!