标签:string pac else const amp cin alt using code
#include<iostream> #include<string> using namespace std; const int Max = 550; int Compare(int a[], int b[]); void Plus(int a[], int b[], int n); void Insert(int a[], int b[]); int main() { int a[Max] = {0}, b[Max] = {0}, step = 0, n; string str1; cin >> n >> str1; int len = str1.size(), i; a[0] = len; for (i = 1; i <= len; i ++) { if (str1[len - i] >= ‘A‘ && str1[len - i] <= ‘F‘) a[i] = str1[len - i] - ‘A‘ + 10; else a[i] = str1[len - i] - ‘0‘; } Insert(a, b); for(step = 0 ; step <= 30; step ++) { if (Compare(a, b) == 0) break; Plus(a, b, n); Insert(a, b); } if (step > 30) cout << "NO"; else cout <<"STEP=" << step << endl; return 0; } int Compare(int a[], int b[]) { int i; for (i = a[0]; i > 0; i --) { if (a[i] > b[i]) return 1; else if (a[i] < b[i]) return -1; } return 0; } void Plus(int a[], int b[], int n) { int i, len = a[0]; for (i = 1; i <= len; i ++) { a[i] = a[i] + b[i]; a[i + 1] += a[i] / n; a[i] = a[i] % n; } if (a[len + 1] != 0) //最高位进位 a[0] ++; } void Insert(int a[], int b[]) { int i, len = a[0]; b[0] = len; for (i = 1; i <= len; i ++) b[i] = a[len - i + 1]; }
标签:string pac else const amp cin alt using code
原文地址:https://www.cnblogs.com/Es-war/p/12449616.html