我遇到了这个问题:
http://www.iarcs.org.in/inoi/contests/oct2005/Advanced-2.php
问题基本上是图表.您将获得一个包含多达70个节点的图形,以及一个邻接矩阵,用于说明两个节点之间存在多少条边.每条边都是双向的.
现在的问题是问你找出的任意两个节点N1和N2之间的固定长度的N个不同路径的数量.路径可以重复.即,路径可以通过已包含的节点.
最天真的算法是运行广度优先搜索并检查Nth层中出现的N2数量,其中BFS树以N1为根.但这不会奏效.
怎么去呢?
我刚刚将一个ip分配给一个char数组并打印出来以确保它是正确的并得到以下结果:
int
main(void)
{
char ip [11] = "65.55.57.27";
printf(ip);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我明白了
65.55.57.270 "
Run Code Online (Sandbox Code Playgroud)
但是,如果我将数组大小增加到12
int
main(void)
{
char ip [12] = "65.55.57.27";
printf(ip);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我明白了
65.55.57.27
Run Code Online (Sandbox Code Playgroud)
有谁能解释一下?为什么大小为11的数组返回13个char结果,而大小为12的数组返回11个char结果?
#include <iostream>
#include <string>
using namespace std;
int main(){
string x;
x = not false and true;
cout << x << endl;
}
Run Code Online (Sandbox Code Playgroud)
为什么这个代码在跑步时输出笑脸?
我写了这个简单的程序,以相反的顺序打印字符串,但它显示分段错误.
#include<stdio.h>
#include<string.h>
int main (int argc, char **argv)
{
char *string;
int n;
printf("Enter a string\n");
scanf("%s",string);
printf("\n");
n = strlen(string);
printf("%d",n);
while(n != 0)
{
printf("%c",string[n]);
n--;
}
return(0);
}
Run Code Online (Sandbox Code Playgroud)
谁能解释我为什么会出现这种分段错误?操作系统:Ubuntu,compilor:gcc
下面的while循环可以在宏中实现吗?
while (x < 0.5)
{
count++;
x = x *2;
}
Run Code Online (Sandbox Code Playgroud)
x是一个非常小的号码.分数
#include <iostream>
#include <fstream>
using namespace std;
const int maxsize=20;
class IntStack{
private:
int element[maxsize],topindex;
public:
IntStack(){topindex=-1;}
int getTI(){
return topindex;
}
int top(){
if(topindex==-1)
exit(-1);
return element[topindex];
}
int top(int *t){
if(topindex==-1)
return -1;
t=&element[topindex];
return 0;
}
int pop(){
if(topindex==-1)
exit(-1);
topindex--;
return element[topindex+1];
}
int pop(int *t){
if(topindex==-1)
return -1;
t=&element[topindex];
topindex--;
return 0;
}
int push(int e){
if(topindex==19)
return -1;
topindex++;
element[topindex]=e;
return 0;
}
inline int empty(){return topindex==-1;}
ostream& print(ostream& o){
for(int i=0;i<=topindex;i++){
o<<element[i]<<' '; …Run Code Online (Sandbox Code Playgroud) 作为这个c/c ++代码:
typedef const char* LPSTR;
Run Code Online (Sandbox Code Playgroud)
我想删除所有空格字符.
我找到了两种方法:
typedef/**/const/**/char*LPSTR; // 1
#define o(s) s
o(typedef)o(const)char*LPSTR; // 2
Run Code Online (Sandbox Code Playgroud)
但我不想做任何新的界限和任何评论.
那么,有第三种方式吗?