-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathms.cpp
More file actions
61 lines (54 loc) · 866 Bytes
/
ms.cpp
File metadata and controls
61 lines (54 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<iostream>
#include<string>
using namespace std;
int pow(int N, int p)
{
if (p == 0)return 1;
return N * pow(N, p - 1);
}
int getDigitCount(int N)
{
if (N == 0)return 0;
return 1 + getDigitCount(N / 10);
}
int getNumericNum(string s)
{
int n = (int)s.length() - 1;
int ans = 0;
int tens = 1;
while (n >= 0)
{
char ch = s[n];
int digi = ch - '0';
if (ans == 0)
ans += digi * tens;
else
{
tens *= 10;
ans += tens * digi;
}
n--;
}
return ans;
}
int modString(string A, int B)
{
int n = (int)A.length() - 1;
long ans = 0;
long tens = 1;
while (n >= 0)
{
char ch = A[n];
int digi = ch - '0';
ans = (ans % B + (digi * tens)%B) % B;
tens = (tens % B * 10 % B) % B;
n--;
}
return ans;
}
int main()
{
cout << "Hello mod string\n";
cout << "mod : " << modString("43535321", 47) << endl;
return 0;
}