2022年5月5日刷题

开干codeforces,日期2022年5月5日,立夏。

目录

3A - Shortest path of the king

5A - Chat Server's Outgoing Traffic


3A - Shortest path of the king



点击打开题目

题目大意:这道题是求从棋盘一个位置到另一个位置的最短距离,可以按照上下左右对角线八个方向进行移动。

题目思路:首先应该把棋盘字母坐标转换为数字判断横纵坐标差值各是多少,由于一步棋可以同时改变横纵坐标,所以移动距离至少为这两个坐标中的最大值。在移动时以坐标相等为终止条件,否则就通过不断比较横纵坐标的大小进行方向判断。

AC代码:

#include<bits/stdc++.h>
#define AC return 0;
using namespace std;
int main(){   
	cin.tie(0);
	ios::sync_with_stdio(0);
	
	string s,t; cin>>s>>t;
	int go=max(abs(int(s[0]-t[0])),abs(int(s[1]-t[1])));
	cout<<go<<endl;
	while(s!=t){
		if(s[0]>t[0]){cout<<'L';s[0]--;}
		else if(s[0]<t[0]){cout<<'R';s[0]++;}
		if(s[1]<t[1]){cout<<'U';s[1]++;}
		else if(s[1]>t[1]){cout<<'D';s[1]--;}
		cout<<endl;
	} 
	                                                                                                                                                                                                                      
    AC
}
//ACplease!!!


/*  printf("                                                                \n");
	printf("                                                                \n");
	printf("       * * *               * * *             * * *             * * *            \n");
	printf("     *       *           *       *         *      *          *       *         \n");
	printf("    *        *          *         *       *        *        *         *        \n");
	printf("            *           *         *                *                  *      \n");
	printf("           *            *         *               *                  *     \n");
	printf("          *             *         *              *                  *       \n");
	printf("         *              *         *             *                  *            \n");
	printf("        *               *         *           *                  *            \n");
	printf("      *                  *       *          *                  *           \n");
	printf("    * * * * * * *          * * *          * * * * * * *      * * * * * * *                           \n");
*/    

5A - Chat Server's Outgoing Traffic

点击打开题目​​​​​​​

题目大意:给定信息,名字前有+则表示将此人加入聊天群,-代表把此人从聊天群删除,
如果名字后边有:则表示此人说话,群中有几个人,则要发送strlen(str)*num个字节,
求通过给定的信息,最终发送的字节数

题目思路:照做呗。

AC代码:

#include<bits/stdc++.h>
#define AC return 0;
using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	string s;
	int ans=0,people=0;
	while(getline(cin,s)){
		if(s[0]=='+') people+=1;
        else if(s[0]=='-') people-=1;
	    else{int place=s.find(':');ans+=people*(s.size()-1-place);}
	}
	cout<<ans;
	AC
	return 0;
}
//ACplease!!!


/*  printf("                                                                \n");
	printf("                                                                \n");
	printf("       * * *               * * *             * * *             * * *            \n");
	printf("     *       *           *       *         *      *          *       *         \n");
	printf("    *        *          *         *       *        *        *         *        \n");
	printf("            *           *         *                *                  *      \n");
	printf("           *            *         *               *                  *     \n");
	printf("          *             *         *              *                  *       \n");
	printf("         *              *         *             *                  *            \n");
	printf("        *               *         *           *                  *            \n");
	printf("      *                  *       *          *                  *           \n");
	printf("    * * * * * * *          * * *          * * * * * * *      * * * * * * *                           \n");
*/    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值