当前位置:网站首页>L1-071 前世档案 (20 分)
L1-071 前世档案 (20 分)
2022-04-22 22:19:00 【WTXYL】
网络世界中时常会遇到这类滑稽的算命小程序,实现原理很简单,随便设计几个问题,根据玩家对每个问题的回答选择一条判断树中的路径(如下图所示),结论就是路径终点对应的那个结点。

现在我们把结论从左到右顺序编号,编号从 1 开始。这里假设回答都是简单的“是”或“否”,又假设回答“是”对应向左的路径,回答“否”对应向右的路径。给定玩家的一系列回答,请你返回其得到的结论的编号。
输入格式:
输入第一行给出两个正整数:N(≤30)为玩家做一次测试要回答的问题数量;M(≤100)为玩家人数。
随后 M 行,每行顺次给出玩家的 N 个回答。这里用 y 代表“是”,用 n 代表“否”。
输出格式:
对每个玩家,在一行中输出其对应的结论的编号。
输入样例:
3 4
yny
nyy
nyn
yyn
输出样例:
3
5
6
2
代码:
#include <iostream>
#include <string>
using namespace std;
int main(){
string s;
int n, m, roots = 0;
cin >> n >> m;
for(int i = 0, j = 1; i < n; i ++, j *= 2)
roots += j;
while(m --){
cin >> s;
int p = 1;
for(int i = 0; i < n; i ++)
if(s[i] == 'y') p *= 2;
else p = p * 2 + 1;
cout << p - roots << endl;
}
}
版权声明
本文为[WTXYL]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_46891900/article/details/124318763
边栏推荐
猜你喜欢

ACL2022 | 利用中文语言层级异质图强化预训练语言模型

Shadowcaster shadowmask map of 0 basic unityurp rendering pipeline is indistinct (code direction)

51 MCU proteus simulation key control nixie tube digital display

Llvm learning (I) - getting to know llvm
![[easy to understand and intensive learning] 1 Introduction](/img/bf/ada1b8c3e8f33621ecb08a813118c5.png)
[easy to understand and intensive learning] 1 Introduction

c#控制台应用添加Log4net日志(控制台和文件)

In the future, platofarm's ecological pass can be logged into bitmart and other four major global platforms

续集:几句简单,但很有用的话

多线程进阶(八)----线程池

CVPR 2022:微笑识别也带性别歧视?浙大武大联合蚂蚁Adobe搞了个公平性提升框架
随机推荐
邀请你参与字节跳动 UME 插件开发竞赛
Wu Enda - deep learning micro course - Lesson 4
[wechat applet development (cloud wallpaper applet tutorial)]
给复杂的数组结构数据换key
接续符介绍及用法和++和--操作符分析介绍及用法
In the future, platofarm's ecological pass can be logged into bitmart and other four major global platforms
[MRCTF2020]Ez_ bypass
fastadmin 跳转后限定搜索条件
Lecture recording and broadcasting | subgraph matching algorithm in graph database - Zou Lei
Appinventor development
=============
GBase 8s V8.8 SQL 指南:教程-6.2
USPS数据集_kmeans使用总结
牛客BM41. 输出二叉树的右视图
讲座录播|图数据库中的子图匹配算法-邹磊
外部中断---------stm32f407zet6
Saiweidian broke on the first day of listing: the market value evaporated by more than 1.5 billion yuan, and the business scale lost slightly
并发的可达性分析(三色标记法)
未来可期,PlatoFarm的生态通证登录Bitmart等全球四大平台
OJ每日一练——下落又弹起的小球