标签:col 包含 include 返回 view 完成 problems submit 直接
yuanjia erbaiyuan wuzhe zhekoujia yibaiyuan wuzhe
200.00 100.00 200.00 100.00
1 #include <iostream> 2 #include<stdio.h> 3 #include<string.h> 4 #include<string> 5 #include<algorithm> 6 #define ll long long 7 using namespace std; 8 #define N 100 9 char arr[20][10]= {"ling","yi","er","san","si","wu","liu","Qi","Ba","jiu", 10 "shi","bAi","qIan","wan" 11 }; //0~9 + 10~13 12 int has[]= {0,1,2,3,4,5,6,7,8,9,10,100,1000,10000,100000000}; //has[14]为亿 13 int d[]= {4,2,2,3,2, 2,3,2,2,3, 3,3,4,3}; //偏移量 14 int solve(char sn[]) 15 { 16 17 string s(sn); 18 int x,len=s.length(); 19 20 21 while(x=s.find("qi"),x>=0&&x<len) //替换qi 和 qian 22 { 23 if(x+2<=len-1&&s[x+2]!=‘a‘) 24 s[x]=‘Q‘; 25 else if(x+2>=len) 26 s[x]=‘Q‘; 27 else 28 s[x+1]=‘I‘; 29 } 30 while(x=s.find("ba"),x>=0&&x<len) //替换Ba 和 bAi 31 { 32 if(x+2<=len-1&&s[x+2]!=‘i‘) 33 s[x]=‘B‘; 34 else if(x+2>=len) 35 s[x]=‘B‘; 36 else 37 s[x+1]=‘A‘; 38 } 39 x=s.find("yuan"); //删掉末尾的 yuan 40 if(x>=0&&x<len) 41 s.erase(x,4); 42 // cout<<s<<" ~~删减yuan后~"<<endl; 43 //特判1亿元 44 x=s.find("yiyi"); 45 if(x>=0&&x<len) 46 return has[14]; 47 48 x=0; 49 len=s.length(); 50 int sum=0,ss=0; 51 while(x<len) 52 { 53 int i=0;//代表是第几个汉字 54 while(i<14&&s.find(arr[i])!=x) 55 i++; 56 if(i==14) //出现错误,反馈error 57 { 58 cout<<"error"<<endl; 59 break; 60 } 61 if(i>=10&&i<=12) 62 { 63 if(ss==0)sum+=has[i]; 64 ss*=has[i],sum+=ss,ss=0; 65 } 66 else if(i==13) 67 sum+=ss,ss=0,sum*=has[13]; 68 else if(i>0) 69 ss=has[i]; 70 71 for(int j=x; j<x+d[i]; j++) //走一步删一步 72 s[j]=‘*‘; 73 x+=d[i]; 74 // printf("***i=%d x=%d ss=%d sum=%d\n",i,x,ss,sum); 75 } 76 return sum+ss; 77 } 78 double get_op(char sn[]) 79 { 80 string s(sn); 81 int x,len=s.length(); 82 double op=0.0; 83 while(x=s.find("qi"),x>=0&&x<len) //替换qi 和 qian 84 { 85 if(x+2<=len-1&&s[x+2]!=‘a‘) 86 s[x]=‘Q‘; 87 else if(x+2>=len) 88 s[x]=‘Q‘; 89 else 90 s[x+1]=‘I‘; 91 } 92 while(x=s.find("ba"),x>=0&&x<len) //替换Ba 和 bAi 93 { 94 if(x+2<=len-1&&s[x+2]!=‘i‘) 95 s[x]=‘B‘; 96 else if(x+2>=len) 97 s[x]=‘B‘; 98 else 99 s[x+1]=‘A‘; 100 } 101 int sum=0,ss=0; 102 x=s.find("zhe"); //删掉末尾的 zhe 103 if(x>=0&&x<len) 104 s.erase(x,4); 105 len=s.length(); 106 x=0; 107 int cnt=0; 108 while(x<len) 109 { 110 int i=0;//代表是第几个个汉字 111 while(i<14&&s.find(arr[i])!=x) 112 i++; 113 if(i==14) 114 { 115 cout<<"error"<<endl; 116 break; 117 } 118 op=op*10.0+has[i]; 119 cnt++; 120 for(int j=x; j<x+d[i]; j++) //走一步删一步 121 s[j]=‘*‘; 122 x+=d[i]; 123 // printf("***i=%d x=%d op=%lf \n",i,x,op); 124 } 125 while(cnt--) 126 op=op*0.1; 127 return op; 128 } 129 int main() 130 { 131 char s1[100],s2[100],s3[100]; 132 while(scanf("%s%s%s",s1,s2,s3)!=EOF) 133 { 134 if(strcmp(s1,"yuanjia")==0) //给的是原价和折扣op 135 { 136 double cost,discost,op; //原价为cost,折扣后的价为discost! 137 cost=solve(s2)*1.0; 138 op=get_op(s3);//printf("op*****%.6lf\n",op); 139 140 discost=cost*op; 141 printf("%.2lf %.2lf\n",cost,discost); 142 } 143 else //给的是折扣价和 折扣op 144 { 145 double cost,discost,op; 146 discost=solve(s2); 147 op=get_op(s3);//printf("op*****%.6lf\n",op); 148 cost=discost/op; 149 printf("%.2lf %.2lf\n",cost,discost); 150 } 151 // printf("****%.4lf\n",1.11/10.00); 152 } 153 154 return 0; 155 }
【ZZNU-oj-2116:人间不值得】(1亿以内的货币拼音转数值求折扣价原价)--hash+String大法好+字符串处理+超大暴力模拟题
标签:col 包含 include 返回 view 完成 problems submit 直接
原文地址:https://www.cnblogs.com/zhazhaacmer/p/9364495.html