Added new GPTs for Black Friday

This commit is contained in:
Your a
2023-11-23 13:00:36 +02:00
7697 changed files with 657492 additions and 69222 deletions
+68
View File
@@ -0,0 +1,68 @@
[![Java Gua Math](https://flow-prompt-covers.s3.us-west-1.amazonaws.com/icon/futuristic/futu_8.png)]()
# Java Gua Math
Solve the famous "gua" math problem using Java code
# Prompt
```
用java实现小明和小丽买瓜,小明差8元,小丽差6元,若两人合买差2元,问瓜多少钱
```
## Conversation
**ASSISTANT**: 以下是一种可能的Java实现方式:
```
public class MelonPrice {
public static void main(String[] args) {
int totalMoney = 0;
for (int price = 1; price <= 100; price++) { // 瓜价从1到100尝试
if ((price * 2 + 2 == price + 8 + price + 6) && (price * 2 + 2 == totalMoney + 2)) {
System.out.println("瓜的价格为:" + price + "元");
break;
}
}
}
}
```
解释一下这段代码。我们可以先假设瓜的价格为price元,然后计算出小明和小丽分别需要付出的钱数:price-8元和price-6元。因为两人合买差2元,所以总共需要付出2(price*2+2)元。
我们用一个for循环来枚举瓜价,从1到100尝试每个可能的值。在每个循环中,我们检查是否满足上述条件,即:
```
price * 2 + 2 == price - 8 + price - 6 + 2 && price * 2 + 2 == totalMoney + 2
```
如果满足,则输出瓜的价格并结束循环。注意,在这里我使用了totalMoney变量来记录小明和小丽实际付出的钱数,以便于最后的判断。
请注意,由于本题没有给出具体的单位(元、美元、欧元等),因此答案的单位也不确定。