CodeForces刷题:Football、Letter、Indian Summer、Codecraft III、Triangular numbers

63 篇文章 7 订阅
7 篇文章 0 订阅

记录洛谷CodeForces刷题QAQ


Football

题面翻译

题面描述

两只足球队比赛,现给你进球情况,问哪支队伍赢了。

第一行一个整数 n n n 1 ≤ n ≤ 100 1\leq n\leq 100 1n100),表示有 n n n 次进球,接下来 n n n 行,每行一个长度不超过 10 10 10,只由大写字母组成的字符串,表示一个进球的球队名,保证只有两个球队。

输出一个字符串表示胜利球队的球队名,不会平局。

题目描述

One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn’t find the overall score of the match; however, he got hold of a profound description of the match’s process. On the whole there are $ n $ lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.

输入格式

The first line contains an integer $ n $ ( $ 1<=n<=100 $ ) — the number of lines in the description. Then follow $ n $ lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.

输出格式

Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.

样例 #1

样例输入 #1

1
ABC

样例输出 #1

ABC

样例 #2

样例输入 #2

5
A
ABA
ABA
A
A

样例输出 #2

A

代码如下

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

int n,i,mzy,zjq;
char srx[21],sry[21],lhy[21];
int main()
{
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {scanf("%s",&srx);
    if(!sry[0])
    strcpy(sry,srx);//为什么要先输入一个呢,这样也可以!
    else if(!lhy[0]||strcmp(srx,sry)!=0)//虽然因为这个原因狂wa7次,加一个CMP的原因是防止前两个进球为同一球队,若先输入一个呢就可以避免(然鹅我并没有)
    strcpy(lhy,srx);
    if(strcmp(srx,sry)==0)
    mzy++;//累加进球数
    else
    zjq++;}
    if(mzy>zjq)
    printf("%s\n",sry);
    else
    printf("%s\n",lhy);
    return 0;
}

Letter

题面翻译

题面描述

Vasya 决定利用报纸上的一段文字写一封匿名信。他可以从报纸上剪下一段文字(或字母),把他们粘贴到匿名信上去。已经剪下的文字不可重复使用。当然,匿名信中的空格不需要剪——他只要在空格处作出标记即可。现在,他知道报纸上的文字 s 1 s1 s1 和他即将写下的匿名信的内容 s 2 s2 s2,请你帮他看看,他能否完成匿名信的书写。

输入格式

两行,分别是 s 1 s1 s1 s 2 s2 s2(无空行),长度不超过 200 200 200,英文字母区分大小写,信中空格不作处理。

输出格式

写的出来就输出YES,否则输出NO

题目描述

Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading $ s_{1} $ and text $ s_{2} $ that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn’t have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.

输入格式

The first line contains a newspaper heading $ s_{1} $ . The second line contains the letter text $ s_{2} $ . $ s_{1} $ и $ s_{2} $ are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.

输出格式

If Vasya can write the given anonymous letter, print YES, otherwise print NO

样例 #1

样例输入 #1

Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog

样例输出 #1

NO

样例 #2

样例输入 #2

Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears

样例输出 #2

YES

样例 #3

样例输入 #3

Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears

样例输出 #3

NO

样例 #4

样例输入 #4

abcdefg hijk
k j i h g f e d c b a

样例输出 #4

YES

代码如下

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

char str[256];//字符串
int a[256];//桶

int main(void){
	register int i;
	gets(str);
	for(i=0;str[i];i++)
		a[str[i]]++;//统计次数
	a[' ']+=256;//极大值
	gets(str);
	for(i=0;str[i];i++)
		if(--a[str[i]]<0)
			return puts("NO"),0;//出现次数多于对应值,输出NO
	puts("YES");//均小于等于对应元素,输出YES
	return 0;
}

Indian Summer

题面翻译

现有 n n n( 1 ≤ n ≤ 100 1 \leq n \leq 100 1n100)片叶子,要求从中选出一些叶子。如果现在的叶子与之前选过的某一片叶子完全相同(即从同一棵树上落下且颜色相同),它就不会被选中。编程找出一共选了多少片叶子。

题目描述

Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn’t take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.

输入格式

The first line contains an integer $ n $ ( $ 1<=n<=100 $ ) — the number of leaves Alyona has found. The next $ n $ lines contain the leaves’ descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than $ 10 $ lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.

输出格式

Output the single number — the number of Alyona’s leaves.

样例 #1

样例输入 #1

5
birch yellow
maple red
birch yellow
maple yellow
maple green

样例输出 #1

4

样例 #2

样例输入 #2

3
oak yellow
oak yellow
oak yellow

样例输出 #2

1

代码如下

#include <iostream>
#include <set>
using namespace std;
struct leaf {
	string type, color;
   // 蒟蒻以前还不知道有这种初始化方式...,这样初始化就可以
   // 不用再创建一个变量然后填充数据了
	leaf(string t, string c) : type(t), color(c) {};
   // 注意这里提供的排序函数,是const {...}
	bool operator<(const leaf& f) const {
      // 我们并不关心set内部元素的排序顺序,所以只用实现下
      // 对比即可
		if (type != f.type) return type > f.type;
		return color > f.color;
	} 
}; 

set<leaf > s;
int main() {
	int n;
	cin >> n;
	string t, c;
	for (int i = 0; i < n; i++) {
		cin >> t >> c;
      // 插入元素,set会帮我们自动去除(废话)
		s.insert((leaf){t, c}); 
	}
    // 最后set的size即是不同元素个数
	cout << s.size();
	return 0;
}

Codecraft III

题面翻译

给你一个月份,问你 k k k 个月后的月份。

月份列表:

January, February, March, April, May, June, July, August, September, October, November, December

输入格式

输入第一行一个字符串 s s s(保证字符串是像列表中那样第一个字母大写,后面小写),第二行一个整数 k k k 1 ≤ k ≤ 100 1 \leq k \leq 100 1k100)。

输出格式

输出一个字符串,表示 k k k 个月后的月份。

题目描述

Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly $ k $ months. He looked at the calendar and learned that at the moment is the month number $ s $ . Vasya immediately got interested in what month Codecraft III will appear. Help him understand that.

All the twelve months in Vasya’s calendar are named using their usual English names: January, February, March, April, May, June, July, August, September, October, November, December.

输入格式

The first input line contains the name of the current month. It is guaranteed that it is a proper English name of one of twelve months. The first letter is uppercase, the rest are lowercase. The second line contains integer $ k $ ( $ 0<=k<=100 $ ) — the number of months left till the appearance of Codecraft III.

输出格式

Print starting from an uppercase letter the name of the month in which the continuation of Codeforces II will appear. The printed name must be contained in the list January, February, March, April, May, June, July, August, September, October, November, December.

样例 #1

样例输入 #1

November
3

样例输出 #1

February

样例 #2

样例输入 #2

May
24

样例输出 #2

May

代码如下

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

int main()
{
    char s[101];
	scanf("%s",&s);
    int y,x;
    if(strcmp(s,"January") == 0)y=1;
    if(strcmp(s,"February") == 0)y=2;
    if(strcmp(s,"March") == 0)y=3;
    if(strcmp(s,"April") == 0)y=4;
    if(strcmp(s,"May") == 0)y=5;
    if(strcmp(s,"June") == 0)y=6;
    if(strcmp(s,"July") == 0)y=7;
    if(strcmp(s,"August") == 0)y=8;
    if(strcmp(s,"September") == 0)y=9;
    if(strcmp(s,"October") == 0)y=10;
    if(strcmp(s,"November") ==0)y=11;
    if(strcmp(s,"December") == 0)y=12;

    scanf("%d",&x);
    x=x+y;
    x=x%12;
    if(x==1)printf("January");
    if(x==2)printf("February");
    if(x==3)printf("March");
    if(x==4)printf("April");
    if(x==5)printf("May");
    if(x==6)printf("June");
    if(x==7)printf("July");
    if(x==8)printf("August");
    if(x==9)printf("September");
    if(x==10)printf("October");
    if(x==11)printf("November");
    if(x==0)printf("December");
    return 0;
}

Triangular numbers

题面翻译

题面描述

给定一个数 n n n,问你是否存在一个整数 i i i,满足 i × ( i + 1 ) 2 = n \frac{i\times (i+1)}{2}=n 2i×(i+1)=n

若存在,输出YES,否则输出NO.

数据范围与约定

1 ≤ n ≤ 500 1 \leq n \leq 500 1n500

题目描述

A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The $ n $ -th triangular number is the number of dots in a triangle with $ n $ dots on a side. . You can learn more about these numbers from Wikipedia (http://en.wikipedia.org/wiki/Triangular_number).

Your task is to find out if a given integer is a triangular number.

输入格式

The first line contains the single number $ n $ ( $ 1<=n<=500 $ ) — the given integer.

输出格式

If the given integer is a triangular number output YES, otherwise output NO.

样例 #1

样例输入 #1

1

样例输出 #1

YES

样例 #2

样例输入 #2

2

样例输出 #2

NO

样例 #3

样例输入 #3

3

样例输出 #3

YES

代码如下

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

double akioi(double p)//计算小数部分
{
	while(p>=1) p-=1;
	return p;
}
int main()
{
	double a;
	scanf("%lf",&a);
	a*=2.0;//*2
    //以下是判断部分
	if(a<=1*2)//分段1
	if(0.5>=akioi(sqrt(a))&&akioi(sqrt(a))>=0.41) printf("YES\n");
	else printf("NO\n");
	else if(a>1*2&&a<=2*3)//分段2
	if(0.5>=akioi(sqrt(a))&&akioi(sqrt(a))>=0.44) printf("YES\n");
	else printf("NO\n");
	else if(a>2*3&&a<=3*4)//分段3
	if(0.5>=akioi(sqrt(a))&&akioi(sqrt(a))>=0.46) printf("YES\n");
	else printf("NO\n");
	else if(a>3*4&&a<=5*6)//分段4
	if(0.5>=akioi(sqrt(a))&&akioi(sqrt(a))>=0.47) printf("YES\n");
	else printf("NO\n");
	else if(a>5*6&&a<=9*10)//分段5
	if(0.5>=akioi(sqrt(a))&&akioi(sqrt(a))>=0.48) printf("YES\n");
	else printf("NO\n");
	else if(a>9*10)//分段6
	if(0.5>=akioi(sqrt(a))&&akioi(sqrt(a))>=0.49) printf("YES\n");
	else printf("NO\n");
	return 0;//完美结束
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值