- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我现在正在应对 CodeEval 上的一项简单挑战。您需要逐行从文件中获取输入,每行包含十六进制数和二进制数,用竖线分隔。目的是把左边所有的十六进制数相加,把右边的二进制数相加,看哪个和大。如果右边(二进制边)大于或等于十六进制边,则打印“True”,否则打印“False”。示例行是“5e 7d 59 | 1101100 10010101 1100111”,输出为真,因为右侧大于左侧。我的代码在我的计算机上打印出正确的输出,但在 CodeEval 上,没有结果输出,我的分数为零。没有列出任何错误。是否存在我看不到的问题?
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <cstdlib>
#include <math.h>
using namespace std;
fstream myFile;
string line;
vector<string> panNums;
int sum1, sum2;
int toDec(string s);
int main(int argc, char *argv[])
{
//open the file
// get numbers by line
myFile.open(argv[1]);
while(getline(myFile, line))
{
//cout << line << endl;
istringstream mystream(line);
string nums;
// read in each number into string nums one by one
// then add that number to the vector that was created
while(mystream)
{
mystream >> nums;
panNums.push_back(nums);
}
bool afterSep = false;
sum1 = 0;
sum2 = 0;
for(int i = 0; i < panNums.size() - 1; i++)
{
stringstream stream;
if(panNums.at(i) == "|")
{
sum1 = sum2;
sum2 = 0;
afterSep = true;
i++;
}
// if true, do stuff
if(afterSep)
{
// deals with the binary side
sum2 += toDec(panNums.at(i));
}
// if false, do other stuff
else
{
// deals with the hexidecimal side
istringstream f(panNums.at(i));
int temp;
// reading hex number into int(AKA converting to int)
f >> hex >> temp;
sum2 += temp;
}
}
// cout << "sum1 " << sum1 << endl;
// cout << "sum2 " << sum2 << endl;
if(sum2 >= sum1)
{
cout << "True" << endl;
}
else
{
cout << "False" << endl;
}
// clear the current vector in order to exclusively have the next line of text stored
panNums.clear();
}
}
int toDec(string s)
{
int num = 0;
int i = s.size() - 1;
// starts at index 0
// which is really the 2^6 or however big the binary number is
for(int a = 0; a < s.size(); a++)
{
if(s.substr(i, 1) == "1")
{
num += pow(2, a);
}
i--;
}
// cout << num << endl;
return num;
}
最佳答案
两台计算机的操作系统是否相同?如果是这样,它们应该没问题,否则您将需要在两个系统上编译,这意味着每个系统都有一个可执行文件。无论如何,当我在 mac 上写东西并想在 mac 和 linux 上运行它时,它在这里仍然有效。
关于c++ - 我的程序可以在我的电脑上运行,但不能在 CodeEval 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37554151/
我正在尝试提交我的 https://www.codeeval.com/open_challenges/158/ 解决方案这是一个冒泡排序。我用 GO lang 编写代码,在我的 PC 上它运行良好且快
这个问题已经有答案了: Arguments to main in C [duplicate] (6 个回答) 已关闭 9 年前。 在 codeeval 中,一些挑战要求我们从文件中读取测试用例,该文件
我一直在为 overlapping rectangles 测试我的代码codeeval 上的挑战。我觉得我的代码接近于解决方案,因为我已经在我的机器上测试过它并且它看起来是正确的。然而,Codeeva
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 9 年前。 Improve t
挑战说明: 有两个序列。第一个序列由数字“0”和“1”组成,第二个序列由字母“A”和“B”组成。挑战在于确定是否可以使用以下规则将给定的二进制序列转换为字符串序列: 1、“0”可以转化为非空字母序列“
挑战描述在这里:https://www.codeeval.com/browse/130/ 两条规则: “0”可以转化为非空字母序列“A”(“A”、“AA”、“AAA”等) “1”可以转换为非空字母序列
这是我在 CodeEval 上遇到的问题。这是我花了 4 个小时解决的问题。两年前我在这里看到了另一篇 CodeEval GridWalk Problem 帖子,但它对我没有任何帮助。如果有人有过这个
Here是挑战的链接。这是为了您的方便: 前缀表达式描述:您将获得一个前缀表达式。编写程序对其进行评估。输入样本:第一个参数将是一个输入文件,每行有一个前缀表达式。例如* + 2 3 4您的程序必须读
我用 C++ 编写了一个小程序,它将一个字符串作为输入。然后它将打印字符串中的第一个非重复字符。下面是我的代码。这是 CodeEval.com 上的挑战。问题是,据我所知,代码按预期工作。但是 Cod
CHALLENGE DESCRIPTION: There are two sequences. The first sequence consists of digits "0" and "1", t
CodeEval 上的 Java 程序必须接受文件路径作为参数。我使用命令行参数来执行此操作,但是当我在 CodeEval 上提交代码时出现如下异常。这个问题有哪些潜在的解决方案? Exception
我正在参与 CodeEval 挑战,以下是其描述: 挑战描述: 我们都记得小时候学习如何使用字母 block 组成不同的单词,例如 MOM、DAD、TRAIN 等。我们建议你暂时提醒一下这个时候,想象
我正在努力学习Java。有一天,我看到一个网站提供在线解决挑战的方法。这是我选择的代码项目:Fizz Buzz 这就是我的项目: import java.io.BufferedReader; impo
我现在正在应对 CodeEval 上的一项简单挑战。您需要逐行从文件中获取输入,每行包含十六进制数和二进制数,用竖线分隔。目的是把左边所有的十六进制数相加,把右边的二进制数相加,看哪个和大。如果右边(
我正在 CodeEval 上用 C 语言进行 fizz buzz 挑战。它在我的电脑上运行良好,但是当我去 CodeEval 上提交时,我遇到了失败和 0 分。它说我有一个缓冲区溢出错误,但它在我的计
所以,我做了 CodeEval 'Longest Lines ' 的问题,它适用于我可以设计的任何输入数据。当我上传到CodeEval时,它说这是错误的。 由于这是一个“中等”问题,因此未提供输入数据
我在 codeeval 上做了一些挑战,当我看到结果时我感到很震惊。 Haskell 结果往往比 C# 解决方案快几倍。我知道这两种语言是不同的,但任何人都可以向我解释(尽可能简单)为什么差异如此之大
所以我现在正在解决 CodeEval 问题,并且由于某种原因,我无法超过 98/100 分数。 以下是 CodeEval 挑战赛的链接: https://www.codeeval.com/open_c
我决定在明年参加正式类(class)之前开始学习 C++,我已经从 CodeEval 和 Project Euler 上的一些简单挑战开始。在这一个中,您必须获取一个包含单词字符串的输入文件,并且您必
我是一名优秀的程序员,十分优秀!