3162. 逻辑或、位或、位亦或

夜神月zxy

include

inline int get_int() {
int ans = 0;
signed char ch = getchar();
bool fuvu = false;
while (ch < ‘0’ || ‘9’ < ch) {
if (ch == ‘-‘)
fuvu = true;
ch = getchar();
}
while (‘0’ <= ch && ch <= ‘9’) {
ans = ans * 10 + ch - ‘0’;
ch = getchar();
}
return fuvu ? -ans : ans;
}

int main() {
int a = get_int(), b = get_int();
printf(“%i\n%i\n%i\n”, a || b, a | b, a ^ b);
}

夜神月zxy

include

inline int get_int() {
int ans = 0;
signed char ch = getchar();
bool fuvu = false;
while (ch < ‘0’ || ‘9’ < ch) {
if (ch == ‘-‘)
fuvu = true;
ch = getchar();
}
while (‘0’ <= ch && ch <= ‘9’) {
ans = ans * 10 + ch - ‘0’;
ch = getchar();
}
return fuvu ? -ans : ans;
}

int main() {
int a = get_int(), b = get_int();
printf(“%i\n%i\n%i\n”, a || b, a | b, a ^ b);
}

Fifnmar

当我看到题面给出的是整数而不是非负整数的时候我就觉得可能有个坑。

果然提交后看了一下数据是有负数的。

一般来说,位运算不会用在 signed 类型上叭!

#include <cstdio>

inline int get_int() {
    int ans = 0;
    signed char ch = getchar();
    bool fuvu = false;
    while (ch < '0' || '9' < ch) {
        if (ch == '-')
            fuvu = true;
        ch = getchar();
    }
    while ('0' <= ch && ch <= '9') {
        ans = ans * 10 + ch - '0';
        ch = getchar();
    }
    return fuvu ? -ans : ans;
}

int main() {
    int a = get_int(), b = get_int();
    printf("%i\n%i\n%i\n", a || b, a | b, a ^ b);
}
你当前正在回复 博客/题目
存在问题!