当前位置:网站首页>L1-071 previous life files (20 points)
L1-071 previous life files (20 points)
2022-04-23 00:06:00 【WTXYL】
This kind of funny fortune telling applet is often encountered in the online world , The implementation principle is very simple , Just design a few questions , Select a path in the judgment tree according to the player's answer to each question ( As shown in the figure below ), The conclusion is the node corresponding to the end of the path .

Now let's number the conclusions from left to right , Number from 1 Start . It is assumed that the answers here are simple “ yes ” or “ no ”, Suppose you answer “ yes ” Corresponding to the left path , answer “ no ” Corresponding to the path to the right . A series of answers for a given player , Please return the number of the conclusion .
Input format :
The first line of input gives two positive integers :N(≤30) The number of questions to answer in a test for players ;M(≤100) For the number of players .
And then M That's ok , Each line gives the player's N answer . Here we use y representative “ yes ”, use n representative “ no ”.
Output format :
For each player , Output the number of its corresponding conclusion in one line .
sample input :
3 4
yny
nyy
nyn
yyn
sample output :
3
5
6
2
Code :
#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://yzsam.com/2022/04/202204222219282034.html
边栏推荐
- Is the securities account of goucai school reliable? Is it safe to open an account now? Which securities firm is better?
- 【leetcode】27. Removing Elements
- [gestion des transactions]
- Select all text
- 【ACM】90. Subset II (the de duplication problem of the same tree layer first needs to sort the array (use sort))
- Interviewer: how big is the performance difference between ArrayList and LinkedList?
- Merge two ordered arrays
- Two color gradients
- 什么是目标关键词?
- Waveform generator based on Multisim
猜你喜欢
随机推荐
3D rotation animation
2022年了,微信商城小程序还值得做吗?
A convnet for the 2020s summary
【事务管理】
Waveform generator based on Multisim
SystemVerilog verification - Test Platform preparation guide learning notes (1): data types
图像感受野的一些理解
Notes on "Introduction to dynamic programming" (under update)
Is the securities account of goucai school reliable? Is it safe to open an account now? Which securities firm is better?
51 single chip microcomputer learning_ 4-2 nixie tube dynamic display
Adaptation des polices
L1-075 obsessive compulsive disorder (10 points)
[VMware] VMware esxi 6.7 installation
Interviewer: how big is the performance difference between ArrayList and LinkedList?
庞加莱球模型
CISSP certified daily knowledge points (April 22, 2022)
WMS系统与ERP仓储管理的差异
常见的社群玩法盘点,你做的是哪一种?
闭包的实现原理和作用、以及内存泄露
重新安装window10






![[necessary knowledge] three dimensional imaging principle of line laser scanning](/img/d9/f59809391f10062448f6f9256ea3c2.png)

