https://www.luogu.com.cn/problem/P3613
运用C语言全部RE请指正
# include <stdio.h>
typedef struct Node{
int q;// q个物品
int s;//格子
}count[50];
int main()
{
//读入m的柜子,k个询问次数
int m,k;
//存放n:0/1,i柜子
int n,i;
int s,q;
struct Node count[50];
scanf("%d %d",&m,&k);
while(k--)
{
scanf("%d %d",&n,&i);
if(n==1)
{
count[i].q = scanf("%d",&q);
count[i].s = scanf("%d",&s);
}
if(n==2)
{
scanf("%d %d",&i,&s);
if(s == count[i].s)
{
printf("%d",count[i].q);
}
}
}
}
想用C语言编译,但是老是出现Runtime error希望大佬们帮忙该错误
应该是写法不规范的问题,尝试修改一下变量的生命位置,以及变量的初始化
count[i].q = scanf("%d",&q);
count[i].s = scanf("%d",&s);
这个代码比较奇葩......你知道scanf返回值代表什么么
改成
scanf("%d",&count[i].q);
scanf("%d",&count[i].s);
另外第5行的count[50]去掉啊,搞出来两个count[50]
运行错误要看你具体都输入啥了,把运行界面截图出来看
count[i].q = scanf("%d",&q);
count[i].s = scanf("%d",&s);
这两句应该是
scanf("%d",&count[i].q);
scanf("%d",&count[i].s);