请问这两种if的写法有什么区别
查看原帖
请问这两种if的写法有什么区别
490554
societyniu_test楼主2021/4/12 16:40
#include<stdio.h>
#include<math.h>
int n, m;
struct person {
	char name[15];
	int dir;
}toy[100005];
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &toy[i].dir);
		scanf("%s", toy[i].name);
	}
	int now = 1;
	for (int i = 1; i <= m; i++) {
		int ai, si;
		scanf("%d%d", &ai, &si);
		if (((toy[now]).dir == 1 && ai == 1) || ((toy[now]).dir == 0 && ai == 0)) now -= si;
		if (((toy[now]).dir == 0 && ai == 1) || ((toy[now]).dir == 1 && ai == 0)) now += si;
		if (now <= 0) now += n;
		if (now > n) now %= n;
	}
	printf("%s", toy[now].name);
}
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
int n, m;
struct person {
	char name[15];
	int dir;
}toy[100005];
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%d", &toy[i].dir);
		scanf("%s", toy[i].name);
	}
	int now = 0;
	for (int i = 1; i <= m; i++) {
		int ai, si;
		scanf("%d%d", &ai, &si);
		if ((toy[now]).dir == 1 && ai == 1) now = (now + n - si) % n;
		else if ((toy[now]).dir == 0 && ai == 0) now = (now + n - si) % n;
		else if ((toy[now]).dir == 0 && ai == 1) now = (now + si) % n;
		else if ((toy[now]).dir == 1 && ai == 0) now = (now + si) % n;
	}
	printf("%s", toy[now].name);
}

一个是把if分开写,一个是用||把条件写在一起,但是第一个wa,第二个ac,请问dl为什么?

2021/4/12 16:40
加载中...