• 个人简介

    、、、C++

    include <iostream>

    include <algorithm>

    include <string>

    using namespace std;

    int a[1005]; int b[1005]; int c[1005];

    string Add(string strA, string strB){ for(int i = 0; i < strA.length(); i ++) a[i] = strA[strA.length() - 1 - i] - '0'; for(int i = 0; i < strB.length(); i ++) b[i] = strB[strB.length() - 1 - i] - '0';

    for(int i = 0; i < max(strA.length(), strB.length()); i ++){
    		c[i] += b[i] + a[i];  //求和
    		c[i + 1] += c[i] / 10;
    		c[i] = c[i] % 10;		 
    }
    
    // 去前导0
    int pos = 0; 
    for(pos = max(strA.length(), strB.length()) + 1; pos > 0; pos --){
    	if(c[pos] != 0) break;
    }
    string ans = "";
    for(int i = pos; i >=0; i --){
    	ans += char(c[i] + '0');
    }
    return ans;
    

    }

    int Compare(string strA, string strB){

    if(strA.length() < strB.length()) return -1;
    if(strA.length() > strB.length()) return 1;
    for(int i = 0; i < strA.length(); i ++){
    	if(strA[i] - '0' < strB[i] - '0' ) return -1;
    	if(strA[i] - '0' > strB[i] - '0' ) return 1;
    }
    return 0;
    

    }

    string Sub(string strA, string strB){

    bool flag = true;  // 正负号的问题 
    if(Compare(strA, strB) == -1){
    	swap(strA, strB);
    	flag = false;
    }
    
    // 字符到数字的问题 
    for(int i = 0; i < strA.length(); i ++)
    	a[i] = strA[strA.length() - 1 - i] - '0';
    for(int i = 0; i < strB.length(); i ++)
    	b[i] = strB[strB.length() - 1 - i] - '0';
    
    // 加减进位的问题 
    for(int i = 0 ; i < max(strA.length(), strB.length()); i ++){
    	c[i] = a[i] - b[i];
    	if(c[i] < 0){   // 判断是否要借位 
    		c[i] += 10; // 借位后+10 
    		c[i + 1] -= 1; // 减 1 
    	}
    }
    // 去前导0的问题 
    int pos = 0; 
    for(pos = max(strA.length(), strB.length()) + 1; pos > 0; pos --){
    	if(c[pos] != 0) break;
    }
    string ans = "";
    for(int i = pos; i >=0; i --){
    	ans += char(c[i] + '0');
    }
    if(flag == false) return "-"+ans;
    return ans;
    

    } string Multi(string strA, string strB){ // 字符到数字的问题 for(int i = 0; i < strA.length(); i ++) a[i] = strA[strA.length() - 1 - i] - '0'; for(int i = 0; i < strB.length(); i ++) b[i] = strB[strB.length() - 1 - i] - '0'; // 乘法进位的问题

    for(int i = 0; i < strA.length(); i ++){
    	for(int j = 0; j < strB.length(); j ++){
    		c[i + j] += (a[i] * b[j]);
    		c[i + j + 1] += c[i + j] / 10;
    		c[i + j] %= 10;
    	}
    }
    // 去前导0
    int pos = 0; 
    for(pos = max(strA.length(), strB.length()) + 1; pos > 0; pos --){
    	if(c[pos] != 0) break;
    }
    string ans = "";
    for(int i = pos; i >=0; i --){
    	ans += char(c[i] + '0');
    }
    return ans;	
    

    } // 高精度/低精度 string Div(string strA, long long B, long long& Mod){ // 字符到数字的问题 for(int i = 0; i < strA.length(); i ++) a[i] = strA[i] - '0'; for(int i = 0; i < strA.length(); i ++){ Mod = Mod * 10 + a[i]; c[i] = Mod / B; Mod %= B; } // 去前导0 int pos = 0; for(pos = 0; pos< strA.length(); pos ++){ if(c[pos] != 0) break; }

    string ans = "";
    for(int i = pos; i < strA.length(); i ++){
    	ans += char(c[i] + '0');
    }
    return ans;	
    

    }

    int main() {

    string A = "15";
    long long B = 4;
    long long Mod = 0;
    cout <<  Div(A,B, Mod) << endl;
    cout << Mod << endl;
    
    
    return 0;
    

    } 、、、

  • 通过的题目

题目标签

语言基础
18
其他
11
高精度
9
位运算
8
选择语句
8
循环语句
6
竞赛
5
进制转换
4
快速幂
3
动态规划
3
USACO
3
二分答案
3
前缀和、差分数组
3
1.5
2
分治
2
NOIP
2
年份
2
一维数组
2
字符串
2
字符数组
2