标签:style blog io ar color os sp for strong
#include <iostream> #include <string.h> #include <sstream> #include <math.h> #include <vector> #include <algorithm> using namespace std; int susuTable[28]={1}; bool isLear(int num) { if(num==2) return true; else { int i = 2; for(;i<=sqrt(num);i++) { if(num%i == 0) return false; } return true; } } void setArr(int arr[]) { int i = 2; int totalBit = 1; while(totalBit!=28) { if(isLear(i) ==true) { arr[totalBit] = i; totalBit++; } i++; } } void display(int arr[]) { int i = 0; for(;i<28;i++) { cout<<arr[i]<<" "; } } long long sparkToInt(string spark) { long long Int_num = 0; int len = spark.length(); if(len == 1) { Int_num = spark[0] - ‘0‘; return Int_num; } int last=0; int i = 0; for(;i<len;i++) if(spark[i]==‘,‘) last++; i = 0; int temp = 0; while(i!=len) { temp = 0; while(spark[i]!=‘,‘ && i!=len) { temp = temp*10 + (int)(spark[i]-‘0‘); i++; } Int_num += temp; Int_num *= susuTable[last--]; if(i==len) break; else { i++; } } return Int_num; } int main() { string num_a,num_b; setArr(susuTable); display(susuTable); //cout<<endl; cin>>num_a>>num_b; while(!(num_a =="0" || num_b=="0")) { long long a = sparkToInt(num_a); long long b = sparkToInt(num_b); //cout<<endl<<a<<" "<<b<<endl; long long add = a+b; //cout<<add<<endl; string result=""; int index = 1; while(add!=0) { ostringstream ost; ost<<add%susuTable[index]; string temp(ost.str()); //result.insert(result.begin(),add%susuTable[index]+""); temp.append(result); result = temp; //result.push_back((char)(add%susuTable[index])); //cout<<add%susuTable[index]; add = add/susuTable[index]; if(add!=0) { result.insert(result.begin(),‘,‘); } index++; } cout<<result<<endl; num_a.clear(); num_b.clear(); cin>>num_a>>num_b; } return 1; }
1,0 2,1 4,2,0 1,2,0 1 10,6,4,2,1 0 0
1,0,1 1,1,1,0 1,0,0,0,0,0
解题思路:
将火星数字提取出来转化成int,再计算2个int的和,在转化成火星数字。
问题:25位火星数字,超过int,甚至long long,未ac
标签:style blog io ar color os sp for strong
原文地址:http://www.cnblogs.com/55open/p/4119553.html