社区讨论

关于namespace 这样做能在Noip中编译通过吗

学术版参与者 8已保存回复 9

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
9 条
当前快照
1 份
快照标识符
@mi7crwus
此快照首次捕获于
2025/11/20 19:33
4 个月前
此快照最后确认于
2025/11/20 19:33
4 个月前
查看原帖
CPP
#include <cstdio>
#include <ctime>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
using namespace std;

namespace _nico {
	int a[1000];
	int queue;
	char y1;
	int n;
	bool next;
	int strlen = 1;
	int stack(int x,int y) {
		return x + y;
	}
	bool memset(int a,int b) {
		return a < b;
	}
	bool fill(int a,int b) {
		return a > b;
	}
	int string(int x,int y) {
		return x - y;
	}
	bool cmp(int x,int y) {
		return x > y;
	}
	void main() {
		freopen("test.in","r",stdin);
		freopen("test.out","w",stdout);
		srand(time(NULL));
		scanf("%d",&n);
		for(int i = 1;i <= n;++i) cin >> a[i];
		//sort(a + 1,a + 1 + n,cmp);
		random_shuffle(a + 1,a + 1 + n);
		if(memset(a[1],a[2])) {
			cout<<stack(a[1],a[2]) << endl;
		}
		if(fill(a[1],a[2])) {
			cout<<string(a[1],a[2])<<endl;
		}
		return ;
	}
}

int main() {
	_nico::main();
}
我这里用了多个常见的已经在库中包含的变量名函数名,
问下Namespace 把程序包含起来是否一定能保证变量名不冲突。
还有在自定义namespace前加using namespace std;应该可以用吧。。

回复

9 条回复,欢迎继续交流。

正在加载回复...