我试图在纯2D阵列上使用memset,使用以下代码:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int l[3][3];
memset (l, 1, sizeof(l));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cout << l[i][j] << " ";
}
cout << endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我希望使用该行将整个数组初始化为1:
memset(l,1,sizeof(l));
但我没有得到预期的值,它给了我以下输出:
16843009 16843009 16843009
16843009 16843009 16843009
16843009 16843009 16843009
Run Code Online (Sandbox Code Playgroud)
认为这可能是编译器问题,所以我尝试使用Ideone:
请帮忙.
我在Topcoder上查看问题的解决方案,并遇到了这个:
http://community.topcoder.com/stat?c=problem_solution&rm=249419&rd=9996&pm=6621&cr=309453
目前我不知道算法是如何工作的,但是代码中"<?="运算符的用法是什么?我尝试在我的机器上编译代码,也在ideone.com上编译,但令我惊讶的是,代码无法编译.运营商做了什么,为什么它不能在像ideone这样的标准编译器上运行,代码在Topcoder上通过了系统测试?
代码在这里:
using namespace std;
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <string>
#include <sstream>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#define PB push_back
#define SZ size()
#define REP(v, hi) for (int v=0; v<(hi); v++)
#define REPD(v, hi) for (int v=((hi)-1); v>=0; v--)
#define FOR(v, lo, hi) for (int v=(lo); v<(hi); v++)
#define FORD(v, lo, hi) for (int v=((hi)-1); v>=(lo); v--)
typedef vector <int> …Run Code Online (Sandbox Code Playgroud)