Skip to content

Instantly share code, notes, and snippets.

@hechien
Created April 5, 2017 15:42
Show Gist options
  • Save hechien/3dd1af17dddc9ee310b18e0ed0e90373 to your computer and use it in GitHub Desktop.
Save hechien/3dd1af17dddc9ee310b18e0ed0e90373 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
using namespace std;
int convert(string,char,char);
int main(void)
{
string input;
const string aux;
int n,place,i,j,t,p;
long long int sum1=0,sum2=0,sum=0;
cin >> input ;
n=input.size();
t=n/2;
int number[n/2];
if(aux+input[0]+input[1]=="負")
{
for(i=2,j=0;i<(n-2),j<(n-2)/2;i+=2,j++)
{
number[j]=convert(aux,input[i],input[i+1]);
}
}
else
for(i=0,j=0;i<n,j<n/2;i+=2,j++)
{
number[j]=convert(aux,input[i],input[i+1]);
}
if((place=input.find("億",0))>=0)
{
if((place=input.find("仟",0))>=0)
{
sum1=sum1+number[0]*number[1];
if((place=input.find("佰",0))>=0)
{
sum1=sum1+number[2]*number[3];
if((place=input.find("拾",0))>=0)
{
sum1=sum1+number[4]*number[5];
if((place=input.find("拾",0))+2!=input.find("億",0))
{
sum1=sum1+number[6];
}
}
else
{
if((place=input.find("零",0))>=0)
{
sum1=sum1+number[5];
}
}
}
else
{
if((place=input.find("拾",0))>=0)
{
sum1=sum1+number[3]*number[4];
if((place=input.find("拾",0))+2!=input.find("億",0))
{
sum1=sum1+number[5];
}
}
}
}
else
{
if((place=input.find("佰",0))>=0)
{
sum1=sum1+number[0]*number[1];
if((place=input.find("拾",0))>=0)
{
sum1=sum1+number[2]*number[3];
if((place=input.find("拾",0))+2!=input.find("億",0))
{
sum1=sum1+number[4];
}
}
}
}
sum1=sum1*100000000;
}
if((place=input.find("億",0))>=0&&(place=input.find("萬",0))>=0)
{
p=input.find("億",0);
if((place=input.find("仟",p))>=0)
{
sum2=sum2+number[p/2+1]*number[p/2+2];
if((place=input.find("佰",p))>=0)
{
sum2=sum2+number[p/2+3]*number[p/2+4];
if((place=input.find("拾",p))>=0)
{
sum2=sum2+number[p/2+5]*number[p/2+6];
if((place=input.find("拾",p))+2!=input.find("萬",0))
{
sum2=sum2+number[p/2+7];
}
}
else
{
if((place=input.find("零",p))>=0)
{
sum2=sum2+number[p/2+6];
}
}
}
else
{
if((place=input.find("拾",p))>=0)
{
sum2=sum2+number[p/2+4]*number[p/2+5];
if((place=input.find("拾",p))+2!=input.find("萬",0))
{
sum2=sum2+number[p/2+6];
}
}
}
}
else
{
if((place=input.find("佰",p))>=0)
{
sum2=sum2+number[p/2+1]*number[p/2+2];
if((place=input.find("拾",p))>=0)
{
sum2=sum2+number[p/2+3]*number[p/2+4];
if((place=input.find("拾",p))+2!=input.find("萬",0))
{
sum2=sum2+number[p/2+5];
}
}
}
}
sum2=sum2*10000;
}
if((place=input.find("億",0))<0&&(place=input.find("萬",0))>=0)
{
if((place=input.find("仟",0))>=0)
{
sum2=sum2+number[0]*number[1];
if((place=input.find("佰",0))>=0)
{
sum2=sum2+number[2]*number[3];
if((place=input.find("拾",0))>=0)
{
sum2=sum2+number[4]*number[5];
if((place=input.find("拾",0))+2!=input.find("萬",0))
{
sum2=sum2+number[6];
}
}
else
{
if((place=input.find("零",0))>=0)
{
sum2=sum2+number[5];
}
}
}
else
{
if((place=input.find("拾",0))>=0)
{
sum2=sum2+number[3]*number[4];
if((place=input.find("拾",0))+2!=input.find("萬",0))
{
sum2=sum2+number[5];
}
}
}
}
else
{
if((place=input.find("佰",0))>=0)
{
sum2=sum2+number[0]*number[1];
if((place=input.find("拾",0))>=0)
{
sum2=sum2+number[2]*number[3];
if((place=input.find("拾",0))+2!=input.find("萬",0))
{
sum2=sum2+number[4];
}
}
}
}
sum2=sum2*10000;
}
if((place=input.find("仟",n))<0)
{
sum=sum+number[t-7]*number[t-6];
if((place=input.find("佰",n))<0)
{
sum=sum+number[t-5]*number[t-4];
if((place=input.find("拾",n))<0)
{
sum=sum+number[t-3]*number[t-2];
if(number[t-1]<10&&number[t-1]>0)
{
sum=sum+number[t-1];
}
}
else
{
if(number[t-1]>0&&number[t-1]<10)
{
sum=sum+number[t-1];
}
}
}
else
{
if((place=input.find("拾",n))>=0)
{
sum=sum+number[3]*number[4];
if(number[5]>0&&number[5]<10)
{
sum=sum+number[5];
}
}
}
}
else
{
if((place=input.find("佰",n))>=0)
{
sum=sum+number[0]*number[1];
if((place=input.find("拾",n))>=0)
{
sum=sum+number[2]*number[3];
if(number[4]>0&&number[4]<10)
{
sum=sum+number[4];
}
}
}
else
{
if((place=input.find("拾",n))>=0)
{
sum=sum+number[0]*number[1];
if(number[2]>0&&number[2]<10)
{
sum=sum+number[2];
}
}
else
{
sum=sum+number[0];
}
}
}
if(aux+input[0]+input[1]=="負")
cout << '-' << sum1+sum2+sum << endl ;
else
cout << sum1+sum2+sum << endl ;
return 0;
}
int convert(string aux,char input1,char input2)
{
string number;
number=aux+input1+input2;
if(number=="壹")
return 1;
else if(number=="貳")
return 2;
else if(number=="參")
return 3;
else if(number=="肆")
return 4;
else if(number=="伍")
return 5;
else if(number=="陸")
return 6;
else if(number=="柒")
return 7;
else if(number=="捌")
return 8;
else if(number=="玖")
return 9;
else if(number=="零")
return 0;
else if(number=="拾")
return 10;
else if(number=="佰")
return 100;
else if(number=="仟")
return 1000;
else if(number=="萬")
return 10000;
else if(number=="億")
return 100000000;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment