我只是想熟悉从Java迁移的C++的基础知识.我刚刚写了这个功能禁止程序,我遇到了一个错误test.cpp:15: error: expected primary-expression before ‘<<’ token,我不知道为什么.
任何人都在意解释为什么endl不使用常数?代码如下.
//Includes to provide functionality.
#include <iostream>
//Uses the standard namespace.
using namespace std;
//Define constants.
#define STRING "C++ is working on this machine usig the GCC/G++ compiler";
//Main function.
int main()
{
string enteredString;
cout << STRING << endl;
cout << "Please enter a String:" << endl;
cin >> enteredString;
cout << "Your String was:" << endl;
cout << enteredString << endl;
return(0);
}
Run Code Online (Sandbox Code Playgroud) 在我开始之前,我想澄清一点,我不是在寻找代码示例来获得答案; 这会击败欧拉计划的目标.
问题可以在http://projecteuler.net/problem=3找到
我想我有办法解决问题,但算法很慢; 它已经运行了将近两个半小时.所以我正在寻找有关优化的一般建议.
谢谢.
#include<iostream>
using namespace std;
bool primality(int);
int main(){
long long lim = 600851475143;
long long div = lim/2;
bool run = true;
while(run){
if(lim%div==0 && primality(div)){
cout << "HPF: " << div;
run = false;
}
else{
div--;
}
if(div<=1){
break;
}
}
return 0;
}
bool primality(int num){
for(int i=2; i<num; i++){
if(num%i==0 && i!=num){
return false;
}
else{
return true;
}
}
}
Run Code Online (Sandbox Code Playgroud) 对于分类问题,通常如何确定网络的输出?
比方说,有三个可能的类,每个类都有一个数字标识符,合理的解决方案是将输出相加并将该总和作为网络的总输出吗?或者你会采取网络输出的平均值?
有很多关于人工神经网络理论的信息,但关于应用程序的信息并不多,但如果这是一个愚蠢的问题,我会大肆宣传.
鉴于以下内容: -
#include <stdlib.h>
#include <stdio.h>
#include "SOM.h"
int N = 10;
int FEATURES = 5;
struct _Node{
int x, y;
double w[];
};
struct Node **nodes;
void main(){
init();
}
void init(){
int i, j;
Node tmp;
nodes = malloc(N * sizeof(Node*));
for(i=0; i<N; i++){
nodes[i] = malloc(N * (2*sizeof(int) + FEATURES*sizeof(double)));
for(j=0; j<N; j++){
nodes[i][j]->x = i; //Troublesome line
nodes[i][j]->y = j; //Troublesome line
nodes[i][j]->w = {0.0, 0.1}; //Troublesome line
}
}
}
void clean(){
//
}
Run Code Online (Sandbox Code Playgroud)
标题: …