http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2833
题意:讲述了一种投小钱赢大钱的赌博方式,初始投入钱m,如果本局赢了,将钱连本带利投入下一局继续赌博。如果本局输了,之前得到的钱全部清零,如果打平,本局不赢钱。每局投入的钱数不能大于一百万,计算连本带利赢得的钱数,如果大于一百万则按赢了一百万。输入t组,然后是初始投入的钱m与赌博的局数n。在n局中,给出每局的Money Line,用于作为比率计算本局赢得的钱数。如果Money Line 大于0,则比率为Money Line/100,结果截取3位小数;否则,比率为100/Money Line,结果截取3位小数。每局赢得的钱数(截取两位小数)=当前投入的赌注*比率。最后得到的钱整数部分按每3位输出一个“,”的形式。
1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <algorithm> 5 #include <stack> 6 using namespace std; 7 const int N=2000010; 8 #define LL long long 9 struct ndoe 10 { 11 LL x; 12 string s; 13 } a[N]; 14 char ss[N]; 15 int main() 16 { 17 int t; 18 scanf("%d",&t); 19 while(t--) 20 { 21 double m; 22 int n; 23 scanf("%lf%d",&m,&n); 24 for (int i = 0; i < n; i++) 25 { 26 cin>>a[i].x>>a[i].s; 27 } 28 LL sum = m*100; 29 for (int i = 0; i < n; i++) 30 { 31 if (a[i].s=="Tie") 32 continue; 33 else if (a[i].s=="Loss") 34 { 35 sum = 0; 36 continue; 37 } 38 else 39 { 40 LL t1,t2; 41 if (a[i].x > 0) 42 { 43 t1 = a[i].x*10; 44 t2 = sum*t1/1000; 45 sum+=t2; 46 } 47 else 48 { 49 t1 = 100*1000/(-a[i].x); 50 t2 = sum*t1/1000; 51 sum+=t2; 52 } 53 } 54 if (sum >= 100000000) sum=100000000; 55 } 56 if (sum >= 100000000) sum=100000000; 57 double ans = sum*0.1/10; 58 sprintf(ss,"%.2f",ans); 59 stack<char>p; 60 int i,cnt = 0; 61 printf("$"); 62 for (i = strlen(ss)-1; i >= 0; --i) 63 { 64 p.push(ss[i]); 65 if (ss[i]==‘.‘) 66 break; 67 } 68 for (int j = i-1; j >= 0; --j) 69 { 70 cnt++; 71 p.push(ss[j]); 72 if (cnt%3==0&&j!=0) 73 p.push(‘,‘); 74 } 75 while(!p.empty()) 76 { 77 char ch = p.top(); 78 printf("%c",ch); 79 p.pop(); 80 } 81 puts(""); 82 } 83 return 0; 84 }
Parlay Wagering,布布扣,bubuko.com
原文:http://www.cnblogs.com/lahblogs/p/3621912.html