Files
python/TangDou/LuoGuBook/P1363_Prepare.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

23 lines
590 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
/**
功能:正数+负数取模
n=3为例
MOD就是一直0,1,2,0,1,2这样的向下走不会乱了规矩
MOD 0 1 2 0 1 2 0 1 2
@ @ @ @ @ @ @ @ @
a -3 -2 -1 0 1 2 3 4 5
*/
int MOD(int a, int b) {
return (a % b + b) % b; //配合数组下标从0开始合适
}
int main() {
int n = 5;
for (int a = -4; a <= 2; a++) {
cout << "a=" << a << " MOD=" << MOD(a, n) << endl;
}
return 0;
}