'commit'
This commit is contained in:
23
TangDou/LuoGuBook/P1363_Prepare.cpp
Normal file
23
TangDou/LuoGuBook/P1363_Prepare.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user