你好,我有以下功能:
Block* Keywords::parseBlock(TiXmlElement* element)
{
double x1 = atoi(element->Attribute("left"));
double y1 = atoi(element->Attribute("top"));
double x2 = atoi(element->Attribute("right"));
double y2 = atoi(element->Attribute("bottom"));
double width = abs(x2 - x1);
int bid = atoi(element->Attribute("id"));
vector<LineElement*> lines;
for (TiXmlElement* sub = element->FirstChildElement("line"); sub; sub = sub->NextSiblingElement("line"))
lines.push_back(parseLine(sub));
return new Block(y2,x2,y1,x1,bid,width, lines);
}///End function parse Block
LineElement* Keywords::parseLine(TiXmlElement* element)
{
double x1 = atoi(element->Attribute("left"));
double y1 = atof(element->Attribute("top"));
double x2 = atoi(element->Attribute("right"));
double y2 = atoi(element->Attribute("bottom"));
int bid = atoi(element->Attribute("id"));
vector<Element*> words;
for (TiXmlElement* sub …Run Code Online (Sandbox Code Playgroud) 我使用以下代码来解决单词的频率://由Briana Morrison编写的Owen程序
//#pragma warning (disable : 4786)
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;
// program assumes that the filename is the only thing passed into program
// if you are using standard argc and argv, then arguments to main should change, and uncomment
// first line.
int main(int argc, char * argv[])
{
string filename(argv[1]);
// string filename;
//cout << "Enter filename" << endl;
//cin >> filename;
ifstream infile(filename.c_str()); …Run Code Online (Sandbox Code Playgroud) 问题:检查向量中的连续元素if v[i] < v[i+1] + 1
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int>v{1,2,3,4,5,6,7,8,9,10};
for(auto &i: v)
{
cout << (i+1) << endl;
}
//SIMILAR TO THIS FOR LOOP
for(int i = 0; i < v.size() - 1;i++)
{
if(v[i] < v[i+1] + 1){cout << "ok" << endl;}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
问题:
for(auto &i: v)我如何使用索引来比较两个连续的元素?我正在使用ARQ来查询本地 RDF 文件。我正在使用的命令如下:
./arq --data /home/datasets/a-m-00027.nt --results CSV --query myQuery.sparql
Run Code Online (Sandbox Code Playgroud)
myQuery.sparql 包含查询:
PREFIX basekb:<http://rdf.basekb.com/ns/>
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?x
FROM </home/data/a-m-00027.nt>
WHERE {?x rdf:type basekb:music.release}
LIMIT 10
Run Code Online (Sandbox Code Playgroud)
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
at java.util.concurrent.CopyOnWriteArrayList.iterator(CopyOnWriteArrayList.java:959)
at com.hp.hpl.jena.graph.impl.SimpleEventManager.notifyAddTriple(SimpleEventManager.java:97)
at com.hp.hpl.jena.graph.impl.GraphBase.notifyAdd(GraphBase.java:124)
at com.hp.hpl.jena.graph.impl.GraphBase.add(GraphBase.java:203)
at com.hp.hpl.jena.sparql.core.DatasetGraphCollection.add(DatasetGraphCollection.java:43)
at com.hp.hpl.jena.sparql.core.DatasetGraphBase.add(DatasetGraphBase.java:82)
at org.apache.jena.riot.system.StreamRDFLib$ParserOutputDataset.triple(StreamRDFLib.java:206)
at org.apache.jena.riot.lang.LangNTriples.runParser(LangNTriples.java:61)
at org.apache.jena.riot.lang.LangBase.parse(LangBase.java:42)
at org.apache.jena.riot.RDFParserRegistry$ReaderRIOTLang.read(RDFParserRegistry.java:185)
at org.apache.jena.riot.RDFDataMgr.process(RDFDataMgr.java:906)
at org.apache.jena.riot.RDFDataMgr.parse(RDFDataMgr.java:687)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:534)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:501)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:454)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:432)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:422)
at arq.cmdline.ModDatasetGeneral.addGraphs(ModDatasetGeneral.java:98)
at arq.cmdline.ModDatasetGeneral.createDataset(ModDatasetGeneral.java:87)
at arq.cmdline.ModDatasetGeneralAssembler.createDataset(ModDatasetGeneralAssembler.java:35)
at arq.cmdline.ModDataset.getDataset(ModDataset.java:34) …Run Code Online (Sandbox Code Playgroud) 我有以下文件:
1,A
2,B
3,C
10000,D
20,E
4000,F
Run Code Online (Sandbox Code Playgroud)
我想选择计数大于10且小于5000的行.输出应该是Ë和˚F.在C++或任何其他语言中都是小菜一碟.我真的想知道如何使用linux命令来完成它.
我尝试了以下命令
awk -F ',' '{$1 >= 10 && $1 < 5000} { count++ } END { print $1,$2}' test.txt
Run Code Online (Sandbox Code Playgroud)
但它只有givine 4000,F.
我们想要搜索Map它是否包含特定的singer.如果是的话,我们将添加disk到list of disks属于singer.如果singer不存在则我们将其添加singer到Map空ArrayList.
地图的结构如下:
Map<Singer,List<Disk>> diskMap = new HashMap<Singer, List<Disk>>();
Run Code Online (Sandbox Code Playgroud)
的键是一个Singer和值的类型的List<Disk>.
代码工作正常.我不明白代码的最后部分:
discography = diskMap.get(singer);
discography.add(disk);
Run Code Online (Sandbox Code Playgroud)
discography.add(disk);用来添加磁盘时.它会在地图中更新吗?public void addDisk(Disk disk){
Singer singer = disk.getSinger();
List<Disk> discography = null;
if(diskMap.get(singer) == null){
diskMap.put(singer, new ArrayList<Disk>());
}
discography = diskMap.get(singer);
discography.add(disk);
}
Run Code Online (Sandbox Code Playgroud) 在以下代码中.我们有一个类TestInners,一个内部类 A,一个方法局部内部类A和一个外A级.
new A().m();输出
中间一样.在代码中.为什么输出中间?首先是对内部类的偏好吗?那么外类呢?我很困惑.
class A { void m() { System.out.println("outer"); } }
public class TestInners {
public static void main(String[] args) {
new TestInners().go();
}
void go() {
new A().m();
class A { void m() { System.out.println("inner"); } }
}
class A { void m() { System.out.println("middle"); } }
}
Run Code Online (Sandbox Code Playgroud) 我有一个排序的字符串向量,我试图找到向量中每个元素的共存:
V = {"AAA","AAA","AAA","BCA",...}
int main()
{
vector<string> vec;
//for every word in the vector
for(size_t i = 0; i < vec.size();i++)
{
int counter = 0;
//loop through the vector and count the coocurrence of this word
for(size_t j = 0; j < vec.size();j++)
{
if(vec[i] == vec[j]) counter +=1;
}
cout << vec[i] << " "<<counter <<ed,l
}
}
Run Code Online (Sandbox Code Playgroud)
复杂性是O(n ^ 2)对吗?这花了很多时间我怎样才能找到解决方法?
谢谢,
这是编辑:
int main()
{
vector<string> vec;
//for every word in the vector
for(size_t i = …Run Code Online (Sandbox Code Playgroud) 我有一个数组A [8] = {0}; 另一个数组B [20] = {0};
我想将所有值从B [12 ... 20]移动到A [0 ... 8].我怎样才能准确地改变指数?有公式吗?所以B [12] - > A [0] B [13] - > A [1]
谢谢.
我正在寻找一个正则表达式,只匹配具有特殊字符和大小为4+的数字字符串.我对这里发布的问题做了一点评论:
测试网站: http ://regexlib.com/RETester.aspx
解: ^((?!.*?\d)(?!.*?[^\w\s]).)+$
我试过这个正则表达式:
解: ([-()_.+ ]*\d[-()_.+ ]*){4,}
此正则表达式与先前的字符串匹配.但是有一个错误.第三个字符串155-555aaa包含字母而不是特殊字符.我们不应该匹配155-555aaa,因为a不是特殊字符.如何修改此正则表达式以仅匹配具有特殊字符的数字字符串.数字字符串可以是任何形式:
例如: 24332-2432 @ 2342-1234
特殊字符:[&〜#"{'[(| -`_ \ç^à@)]} =} ^¨$$*%ù]
数字 =数字
根据以下文章:为什么在范围结束时调用析构函数?
使用new创建对象然后在同一范围的末尾删除它的代码是丑陋的,容易出错,效率低下,并且通常不是异常安全的.例如:
void very_bad_func() // ugly, error-prone, and inefficient
{
X* p = new X;
// use p
delete p; // not exception-safe
}
Run Code Online (Sandbox Code Playgroud)
我正在创建一个类型的对象,TiXmlDocument并在函数的末尾删除它.
void DataLoader::readXmlFile(const string & file)
{
TiXmlDocument *doc = new TiXmlDocument(file.c_str());
bool loadOkay = doc->LoadFile();
TiXmlHandle hdl(doc);
//work is done in here
if(loadOkay)
{
TiXmlElement * pRoot = hdl.FirstChildElement().Element();//.FirstChildElement().Element();
parseFile(pRoot);
}
else
{
cout <<"Error: "<< doc->ErrorDesc()<<endl;
}
//deallocate doc
delete doc;
}
Run Code Online (Sandbox Code Playgroud)
DataLoader::~DataLoader() {}在离开函数范围后,我应该使用析构函数来确保删除对象吗?无需明确删除它delete doc.建议我做了以下事情: …
我们正在学习UML课程.老师说:
如果每个类都充当其派生类的基类,则应将其声明为abstract.
在下图中,假设我们要获得class german shepherd并class labrador从class chien (Dog woof woof).是否有义务class chien成为一个抽象的阶级?
我想对for循环进行基准测试.我决定将for循环中的变量增加100并相应地测量时间.
#include <cstdio>
#include <ctime>
#include <time.h>
#include <iostream>
#include <random>
#include <iomanip> // std::setprecision
using namespace std;
double difference(timespec start, timespec end);
int main()
{
timespec time1, time2;
for(int limit = 0; x < 100000; limit+= 100)
{
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
int temp = 0;
for (int i = 0; i< limit; i++)
temp+=temp;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2);
std::cout << std::fixed;
std::cout << std::setprecision(5);
cout<<x <<" " << difference(time1,time2)<<endl;
}
return 0;
}
double difference(timespec start, timespec end)
{
timespec temp;
if …Run Code Online (Sandbox Code Playgroud)