请找出我的代码中的错误,它在提交得到错误答案的同时仍然适用于我的所有测试用例
Please find out the error in my code it is working for all my test cases still while submitting getting the wrong answer
这是问题的链接 https://www.codechef.com/JUNE20B/problems/CHFICRM 我写了两个不同的代码,根据我的说法,它们都工作正常,但仍然得到错误的答案,这是我的第二种方法。 https://www.codechef.com/JUNE20B/problems/CHFICRM 请有些人可以帮助我 ou.....
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int n,k;
cin>>n;
k=5;
stack<int> s;
int b=1;
for(int i=0;i<n;i++)
{
int d;
cin>>d;
int y;
y=d-k;
if(y==0)
{
s.push(d);
continue;
}
if(s.empty() && d>5)
{
b--;
cout<<"NO"<<endl;
break;
}
while(!s.empty())
{
int z=y-s.top();
if(z==0)
{
s.pop();
s.push(d);
break;
}
else if(z>0){
s.pop();
if(s.empty())
{
cout<<"NO"<<endl;
b--;
break;
}
continue;
}
else if(z<0){
cout<<"NO"<<endl;
b--;
break;
}
}
if(b==0)
{
break;
}
}
if(b)
cout<<"YES"<<endl;
}
return 0;
}
在实践中,似乎需要一个简单的迭代过程。
在给定的时刻,只需计算可用的"5"硬币和"10"硬币的数量。
#include <iostream>
#include <vector>
int main() {
int t;
std::cin >> t;
while (t--) {
int n;
std::cin >> n;
std::vector<int> arr(n);
for (int i = 0; i < n; ++i) {
std::cin >> arr[i];
}
int c5 = 0, c10 = 0;
bool success = true;
for (int i = 0; (i < n) && success; ++i) {
switch (arr[i]) {
case(5):
c5++;
break;
case (10):
c10++;
c5--;
break;
case (15):
if (c10) {
c10--;
} else {
c5 -= 2;
}
}
success = (c5 >= 0) && (c10 >= 0);
}
if (success) std::cout << "YESn";
else std::cout << "NOn";
}
}
相关文章:
- 我的字符计数代码计算错误.为什么
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 0-1背包代码中的错误.我的代码中有什么错误
- 当我的阵列太大时出现分段错误
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- 错误-我无法在VS2019中打开新的Qt项目
- 模板,函数使用错误的构造函数来复制我的对象
- 是否值得降低我的代码的可读性,以便在出现内存不足错误时提供异常安全性?
- 我的 int main() 中出现堆栈溢出错误
- 为什么我的 heap.h 文件给我一个LNK2001错误?
- 无法在我的堆排序代码中找到错误.无法正确执行.C++
- C++出现控制台错误.我无法识别源代码的问题
- 我的固定时间步长与增量时间和插值的解决方案是错误的吗?
- 我的模板类方法返回错误类型?
- 为什么在我的 main 函数中声明整数后我的整数数组中会出现错误?
- C++为什么我的编译器成功了,但我的计算机给出了调试错误?
- 为什么在尝试测量函数返回所需的时间时,我的运行时编号是错误的?
- 为什么我会得到细分错误:我的C 程序中的11个
- C++ BST 内存错误 - 我的删除有什么问题?