vector<int> mul(vector<int> &A, int b){ vector<int> C; int t = 0; for(int i = 0 ;i < A.size() || t; i++){ if (i < A.size()) t += A[i] * b; C.push_back(t % 10); t /= 10; } return C; }
vector<int> mul(vector<int> &A, int b){ vector<int> C; int t = 0; for(int i = 0 ;i < A.size() || t; i++){ if (i < A.size()) t += A[i] * b; C.push_back(t % 10); t /= 10; } return C; }
intmain(){ string a; int b; cin >> a >> b; vector<int> A; for(int i=a.size()-1; i>=0; i--) A.push_back(a[i] - '0'); auto C=mul(A, b); for(int i = C.size() - 1;i>=0 ;i--) printf("%d",C[i]); return0 ; }
#include<stdio.h> #include<string.h> #define N 100010
char s1[N]; char s2[10]; int a[N];
voidreverse(int len, int num) { for (int i = 0; i < len; i++) { //把'1'换成1 s1[i] = s1[i] - '0'; } int i = 0, j = len - 1; //将s1反过来 while(i < j) { int t = s1[i]; s1[i] = s1[j]; s1[j] = t; i++, j--; } for (i = 0; i < len; i++) { //从低位开始乘,每一位都乘上num int t = s1[i] * num + a[i]; //加a[i]是因为前一有进位的话,a[i]不为0 a[i] = t % 10; a[i + 1] += t / 10; //进位 } while (!a[i]) i--; //去掉前导0 if(i < 0) printf("0"); //答案为0,前导0就全部去掉了,i=-1 for ( ; i >= 0; i--) printf("%d", a[i]); //从高位输出 puts(""); }
intmain() { scanf("%s%s", s1, s2); int len1 = strlen(s1); int len2 = strlen(s2); int num = 0; for (int i = 0; i < len2; i++) { //把第二个数转成int num = num * 10 + (s2[i] - '0'); } reverse(len1, num); return0; }