我编写了一个简单的C++(11)程序来测试 Windows 中 Visual Studio Code 中的调试器。我使用 MinGW 发行版作为编译器选项。我已经按照此处的文档进行了设置tasks.json:launch.jsonhttps:
//code.visualstudio.com/docs/cpp/config-mingw
这是示例cpp代码:
typedef std::vector<int> vi;
int main(int argc, char const *argv[])
{
fast();
int tests = 1;
cin >> tests;
while(tests--)
{
int n = 5, k = 25;
cin >> n >> k;
vi permutation(n);
for (int i = 0; i < n; i++)
{
cin >> permutation[i];
}
// vi permutation = {5,4,3,2,1};
auto ans = solve(permutation, k);
// other logic goes here …Run Code Online (Sandbox Code Playgroud) 抱歉问了一个简单的问题。我想将 case 类传递给函数参数,并且我想在函数内部进一步使用它。到目前为止我有试过这个TypeTag和ClassTag,但由于某些原因,我无法正确地使用它或可我不看正确的位置。
用例与此类似:
case class infoData(colA:Int,colB:String)
case class someOtherData(col1:String,col2:String,col3:Int)
def readCsv[T:???](path:String,passedCaseClass:???): Dataset[???] = {
sqlContext
.read
.option("header", "true")
.csv(path)
.as[passedCaseClass]
}
Run Code Online (Sandbox Code Playgroud)
它将被称为这样的:
val infoDf = readCsv("/src/main/info.csv",infoData)
val otherDf = readCsv("/src/main/someOtherData.csv",someOtherData)
Run Code Online (Sandbox Code Playgroud) 我有一个 CSV 文件,其中最后一列位于括号内,并且值以逗号分隔。最后一列中值的数量是可变的。当我将它们读为带有一些列名称的 Dataframe 时,如下所示,我得到了Exception in thread "main" java.lang.IllegalArgumentException: requirement failed: The number of columns doesn't match. 我的 CSV 文件如下所示
a1,b1,true,2017-05-16T07:00:41.0000000,2.5,(c1,d1,e1)
a2,b2,true,2017-05-26T07:00:42.0000000,0.5,(c2,d2,e2,f2,g2)
a2,b2,true,2017-05-26T07:00:42.0000000,0.5,(c2)
a2,b2,true,2017-05-26T07:00:42.0000000,0.5,(c2,d2)
a2,b2,true,2017-05-26T07:00:42.0000000,0.5,(c2,d2,e2)
a2,b2,true,2017-05-26T07:00:42.0000000,0.5,(c2,d2,e2,k2,f2)
Run Code Online (Sandbox Code Playgroud)
我最终想要的是这样的:
root
|-- MId: string (nullable = true)
|-- PId: string (nullable = true)
|-- IsTeacher: boolean(nullable = true)
|-- STime: datetype(nullable = true)
|-- TotalMinutes: double(nullable = true)
|-- SomeArrayHeader: array<string>(nullable = true)
Run Code Online (Sandbox Code Playgroud)
到目前为止我已经编写了以下代码:
val infoDF =
sqlContext.read.format("csv")
.option("header", "false")
.load(inputPath)
.toDF(
"MId",
"PId",
"IsTeacher",
"STime",
"TotalMinutes",
"SomeArrayHeader")
Run Code Online (Sandbox Code Playgroud)
我想在不给出列名的情况下阅读它们,然后将第五列之后的列转换为数组类型。但后来我遇到了括号的问题。有没有一种方法可以在阅读并告知括号内的字段实际上是数组类型的一个字段时执行此操作。
有一个很大的字符串.我想在不同的变量中存储不同的部分.但似乎我的理解不清楚或存在错误.请帮忙.
这是我的代码部分.
char sample[] = "abc,batsman,2,28.0,1800";
char name[10] ,speciality[10];
float batavg;
int pos, runs,j;
j = sscanf(sample,"%s,%s,%d,%f,%d", name, speciality, pos, batavg, runs);
printf("%s,%s,%d,%f,%d", name, speciality, pos, batavg, runs);
printf("\n%d\n",j);
Run Code Online (Sandbox Code Playgroud)
产量
在上面的例子中显示了一些值为j = 1的垃圾值.
我该如何解决这个问题?