栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【Codeforces】A组刷题记录(8 / 206)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【Codeforces】A组刷题记录(8 / 206)

目录

A1. Presents

rzt A2. Vanya and Fence

rzt A3. Anton and Danik

rzt A4. Bear and Big Brother

rzt A5. Team

A6. Beautiful Matrix

A7. Gravity Flip

A8. Petya and Strings


A1. Presents

Problem - A - Codeforces

题意

第一行输入朋友个数

第二行输入每个人要把礼物给谁

输出每个人收到谁给的礼物

//我的代码
#include 
using namespace std;
 
int main()
{
    int n,a[101];
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
        
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
             if(a[j]==i) cout << j << ' ';
}
#include 
using namespace std;

int main()
{
	int i,n;
	int a[101];
	int b[101];
	cin >> n;
	for(i=1;i<=n;i++)
	{
		cin >> a[i];
		b[a[i]]=i;
	}
	for(i=1;i<=n;i++)
        cout << b[i] << ' ';
	return 0;
}

rzt A2. Vanya and Fence

Problem - A - Codeforces

题意:

第一行输入n个人,篱笆高度h

第二行输入每个人的身高

如果该人身高>h,则sum+=2 ,反之sum+=1

#include 
using namespace std;

int main()
{
    int n,h,a[1001],sum=0;
    cin >> n >> h;
    for(int i=0;i> a[i];
        if(a[i]>h) sum+=2;
        else sum+=1;
    }

    cout << sum;
}

rzt A3. Anton and Danik

Problem - A - Codeforces

题意:

第一行输入玩几局

第二行输入 A代表Anton赢 D代表Danik赢

输出谁赢 或者平局

#include 
using namespace std;

int main()
{
    int n,a=0,d=0;
    char ch;
    cin >> n;
    while(n--)
    {
        cin >> ch;
        if(ch == 'A') a++;
        else d++;
    }

    if(a>d) cout << "Anton";
    else if(a==d) cout << "Friendship";
    else cout << "Danik";
}

rzt A4. Bear and Big Brother

Problem - A - Codeforces

题意:

输入两人体重a和b,a以每年3倍增长,b以每年2倍增长

输出几年后 a超过b

其中a=b时也算一年

#include 
using namespace std;

int main()
{
    int a,b,year=0;
    cin >> a >> b;
    if(a==b)
    {
        cout << '1';
        return 0;
    }
    while(a <= b)
    {
        year+=1;
        a*=3;
        b*=2;
    }
    cout << year;
}

rzt A5. Team

Problem - A - Codeforces

题意:

第一行输入n个问题

接下来n行 输入三个人的答案 1表示会 0表示不会

如果超过两个人会 则该问题能解决,反之无法解决

输出能解决的问题个数

#include 
using namespace std;

int main()
{
    int n,a[3],cnt=0;
    cin >> n;
    while(n--)
    {
        int sum=0;
        for(int i=0;i<3;i++)
        {
            cin >> a[i];
            sum+=a[i];
        }
        if(sum>=2) cnt++;
    }
    cout << cnt;
}

A6. Beautiful Matrix

Problem - A - Codeforces

题解:

输入一个5×5的矩阵  题目保证24个元素是0 1个元素是其他数

优美矩阵指非0元素在中心位置

输出移动几次能把非0元素移到中心位置

#include 
#include 
using namespace std;

int main()
{
    int a[5][5],m,n;
    for(int i=0;i<5;i++)
        for(int j=0;j<5;j++)
        {
            cin >> a[i][j];
            if(a[i][j]!=0) m=i,n=j;
        }
    cout << abs(m-2)+abs(n-2);
}

A7. Gravity Flip

Problem - A - Codeforces

题意:

就是sort 降序排序

#include 
#include 
using namespace std;

bool cmp(int a,int b)
{
    return a> n;
    for(int i=0;i> a[i];
    sort(a,a+n,cmp);
    for(int i=0;i 

 

A8. Petya and Strings

Problem - A - Codeforces

题意: 

比较两字符串大小 不区分大小写 

相同输出0    a比b小输出-1    b比a小输出1

用compare()函数

#include 
#include 
using namespace std;

int main()
{
    string a,b;
    cin >> a >> b;
    for(int i=0;i='A'&&a[i]<='Z') a[i]+=32;
        if(b[i]>='A'&&b[i]<='Z') b[i]+=32;
    }
    cout << a.compare(b);
}

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/889883.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号