nums = [1,3,-1,-3,5,3,6,7], k = 3
将上述输入转换为c++的输入
vector<int> split(const string& str, char sep)
{
vector<int> tokens;
int i;
stringstream ss(str);
while (ss >> i) {
tokens.push_back(i);
if (ss.peek() == sep) {
ss.ignore();
}
}
return tokens;
}
int main() {
//读取含有空格的一行字符串
string s;
getline(cin, s);
//读取nums
int start = -1, end = -1;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '[')
start = i;
if (s[i] == ']')
end = i;
}
string temp=s.substr(start+1,end-start-1);
vector<int> nums = split(temp, ',');
//读取k
for (int i = s.size() - 1; i >= 0; --i)
if (s[i] == '=') {
end = i; break;
}
temp = s.substr(end + 1, end - s.size() );
stringstream ss(temp);
int k;
ss >> k;
return 0;
}
java大整数模板
import java.util.*;
import java.math.BigInteger;
public class Main{
public static void main(String args[]){
Scanner cin=new Scanner(System.in);
BigInteger a,b;
a=cin.nextBigInteger();
b=cin.nextBigInteger();
System.out.println(a.add(b));//加法
System.out.println(a.subtract(b));//减法
System.out.println(a.multiply(b));//乘法
System.out.println(a.divide(b));//除法
}
}
public String cal (String minuend, String subtrahend) {
// String minuend="12345",subtrahend="54321";
BigInteger b1 = new BigInteger(minuend);
BigInteger b2 = new BigInteger(subtrahend);
return b1.subtract(b2).toString();
}