首页 > 其他分享 >假币问题

假币问题

时间:2023-07-11 23:00:18浏览次数:16  
标签:tmp Right return string 问题 Result 假币 now

 

题解:

  思路:将A~L每个字母都枚举一遍(每个字母都有轻和重两种状态),看看是否符合输入数据条件

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 string Left[3], Right[3], Result[3];
 5 
 6 bool check(char coin, bool weight) // weight = 1表示判断轻,0表示重
 7 {
 8     string tmp;
 9     tmp.push_back(coin);
10 
11     for (int i = 0; i < 3; ++i)
12     {
13         string l = Left[i], r = Right[i];
14         if (!weight)
15             swap(l, r);
16 
17         switch (Result[i][0])
18         {
19         case 'e':
20             if (l.find(tmp) != string::npos || r.find(tmp) != string::npos)
21                 return 0;
22             break;
23         case 'u':
24             if (r.find(tmp) == string::npos)
25                 return 0;
26             break;
27         case 'd':
28             if (l.find(tmp) == string::npos)
29                 return 0;
30             break;
31         default:
32             break;
33         }
34     }
35     return 1;
36 }
37 
38 int main()
39 {
40     int t;
41     cin >> t;
42     while (t--)
43     {
44         for (int i = 0; i < 3; ++i)
45             cin >> Left[i] >> Right[i] >> Result[i];
46         for (char now = 'A'; now <= 'L'; ++now)
47         {
48             if (check(now, 1))
49             {
50                 cout << now << " is the counterfeit coin and it is light. " << endl;
51                 break;
52             }
53             if (check(now, 0))
54             {
55                 cout << now << " is the counterfeit coin and it is heavy. " << endl;
56                 break;
57             }
58         }
59     }
60     return 0;
61 }

 

以下是python代码:

 1 def check(coin, weight):
 2     tmp = coin
 3 
 4     for i in range(3):
 5         l = Left[i] if weight == 1 else Right[i]  # 类似于c中的三目运算符
 6         r = Right[i] if weight == 1 else Left[i]
 7 
 8         if Result[i][0] == 'e':
 9             if tmp in l or tmp in r:
10                 return False
11         elif Result[i][0] == 'u':
12             if tmp not in r:
13                 return False
14         elif Result[i][0] == 'd':
15             if tmp not in l:
16                 return False
17 
18     return True
19 
20 
21 t = int(input())
22 while t > 0:
23     t -= 1
24     Left = [0] * 3
25     Right = [0] * 3
26     Result = [0] * 3
27 
28     for i in range(3):
29         Left[i], Right[i], Result[i] = input().split()  # 注意这种输入法
30     letter = 'ABCDEFGHIJKL'
31     for now in letter:
32         if check(now, 1):
33             print("{} is the counterfeit coin and it is light. ".format(now))
34             break
35         elif check(now, 0):
36             print(now + " is the counterfeit coin and it is heavy. ")
37             break

 

标签:tmp,Right,return,string,问题,Result,假币,now
From: https://www.cnblogs.com/nijigasaki14/p/17546199.html

相关文章

  • tsconfig.json语法检查问题
    前言:这个问题卡住好久。全是红色波浪线,代码没法看。第一步:"compilerOptions":{"moduleResolution":"node","jsx":"react"},解决办法:https://stackoverflow.com/questions/40899868/typescript-cannot-find-module-react消除了一部分,但一部分还是报错 ......
  • 谷歌浏览器Charset扩展程序(解决Google浏览器没有编码的问题)
    较新的谷歌浏览器没有编码这一项,可以选择添加插件的方式,如果无法访问chrome应用商店,请看本文最后的链接下载。将下载好的扩展程序解压,并添加该文件夹。就能看到Charset了。 可以设置了。 下载链接:链接:https://pan.baidu.com/s/1qy53aI6AgCuXUEB0fAb4aQ提取......
  • MRS_关于HardFault问题查找思路
    不少工程师在项目开发过程中会遇到代码运行进HardFault_Handler中断的情况。因进HardFault_Handler中断的原因(RAM溢出/空指针异常/堆栈溢出等等)比较多,情况比较复杂,搞得工程师没有头绪。现提供排查思路如下:HardFault_Handler定位:可在voidHardFault_Handler(void)中断服务函数中......
  • 红包分配问题
    红包分配问题给你一个整数表示红包的总额,和另一个整数表示红包的个数表示我们要把总金额,随机分成N个红包。要求1:每个红包的金额都是随机的要求2:每个人至少1分钱 示例代码:1publicclassTest2{2publicstaticvoidmain(String[]args){3System.out......
  • django_filters/rest_framework/form.html的报错问题
    报错问题:django_filters/rest_framework/form.htm报错原因为:1没有装django_filters模块使用pip安装pipinstalldjango-filter2模块没有在配置文件中注册:将django_filters添加到installed_apps中INSTALLED_APPS=[...'django_filters',] ......
  • mybatis中数据库字段和实体类的属性映射问题
    由于数据库中表的列名一般是按照多个单词之间用下划线隔开,而java一般是驼峰命名法,所以这两者之间存在映射不到的问题,解决方案如下:1.给字段添加别名,如下:<selectid="getManagerInfo"resultType="string">selectlast_login_timelastLoginTimefromwy_manager......
  • element-ui带输入建议的input框踩坑(输入建议空白以及会闪出上一次的输入建议问题)
    element-ui带输入建议的input框踩坑(输入建议空白以及会闪出上一次的输入建议问题)原文链接:https://blog.csdn.net/wyhstars/article/details/81672195前段时间,在实现带输入建议并且支持模糊查询输入框的时候,发现了两个值得注意的小地方。整理出来,以供借鉴。废话不多说,直......
  • 【开机10】解决出现问题,你的PIN不可用,单击以重新设置PIN 无法打开相机 设置我的PIN 登
    \(弄了1.5个小时,找到这个视频,终于弄好了!!!!!!\)\(如果各位基友出现这种问题,可以参考。\)【开机10】解决出现问题,你的PIN不可用,单击以重新设置PIN无法打开相机设置我的PIN登录选项诊断启动禁用服务后问题解决......
  • 【C++学习笔记——前置声明:解决嵌套引用问题】
    在代码中,两个类相互引用的问题,那么我们就需要在头文件中相互写#include,这样会造成相互循环cpoy头文件,编译器报错,为了解决这个问题,设置了前置声明这个方法。A.h#ifndefA_H#defineA_HclassBclassA{typedefvector<string>::sizetypesize_type;B*b;}#endifB.h#if......
  • 适配器模式解决数据格式适配问题
    @RestController@RequestMapping("/ClientUserAssist/")publicclassClientUserAssistController{@AutowiredClientUserAssistMapperclientUserAssistMapper;/**子系统数据导入接口**/@Transactional(rollbackFor=Exception.class)@PostMa......