为什么操作类型用char定义会出错
查看原帖
为什么操作类型用char定义会出错
313674
epiphanyer楼主2022/8/4 15:52

原来的代码

#include <bits/stdc++.h>
#include <vector>
using namespace std;
int n,q,x,y,k;
char op;
int main(){
	scanf("%d%d",&n,&q);
	vector <vector <int> > ca(n+1); 
	while(q--){
		scanf("%c",&op);
		if(op=='1'){
			scanf("%d%d%d",&x,&y,&k);
			if(ca[x].size()<y+1)ca[x].resize(y+1);
			ca[x][y]=k;
		}
		else{
			scanf("%d%d",&x,&y);
			printf("%d\n",ca[x][y]);
		}
	}
	return 0;
}

输完第二行就会停止运行

AC的代码

#include <bits/stdc++.h>
#include <vector>
using namespace std;
int n,q,x,y,k,op;
int main(){
	scanf("%d%d",&n,&q);
	vector <vector <int> > ca(n+1); 
	while(q--){
		scanf("%d",&op);
		if(op==1){
			scanf("%d%d%d",&x,&y,&k);
			if(ca[x].size()<y+1)ca[x].resize(y+1);
			ca[x][y]=k;
		}
		else{
			scanf("%d%d",&x,&y);
			printf("%d\n",ca[x][y]);
		}
	}
	return 0;
}

只是把op的char改成int了为什么差别这么大 求解 (名字不太危,谢绝提醒

2022/8/4 15:52
加载中...