PAT 甲级 1011 World Cup Betting
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 5 void betAns(char c[], int n,int index); 6 int main() { 7 //std::cout << "Hello, World!" << std::endl; 8 int cnt=0,flag=1; 9 double rate[3][4],tmp[4],sum=1; 10 char ans[4]; 11 for (int i = 0; i < 3; ++i) { 12 13 for (int j = 0; j < 3; ++j) { 14 scanf("%lf",&rate[i][j]); 15 if (flag){ 16 tmp[cnt]=rate[i][j]; 17 betAns(ans,j,cnt); 18 flag=0; 19 } 20 if(rate[i][j]>tmp[cnt]){ 21 tmp[cnt]=rate[i][j]; 22 betAns(ans,j,cnt); 23 } 24 } 25 26 cnt++; 27 28 } 29 cnt=0; 30 for (int i = 0; i < 3; ++i) { 31 sum*=tmp[cnt++]; 32 } 33 sum=(sum*0.65-1)*2; 34 for (int i = 0; i < 3; ++i) { 35 printf("%c ",ans[i]); 36 37 } 38 printf("%.2lf",sum); 39 return 0; 40 } 41 42 void betAns(char c[], int n,int index) 43 { 44 if (n==0){ 45 c[index]='W'; 46 }else if(n==1){ 47 c[index]='T'; 48 }else { 49 c[index]='L'; 50 } 51 52 }
我的
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <cstdio> 2 3 int main() 4 { 5 int n; 6 char s[3]={'W','T','L'}; 7 double m[3]={-1},t; 8 for(int i=0;i<3;++i) 9 { 10 int index=0; 11 double maxp=-1; 12 for(int j=0;j<3;++j) 13 { 14 scanf("%lf",&t); 15 if(t>maxp) 16 { 17 maxp=t; 18 index=j; 19 } 20 } 21 m[i]=maxp; 22 printf("%c ",s[index]); 23 } 24 double ans=(m[0]*m[1]*m[2]*0.65-1)*2; 25 printf("%.2f\n",ans); 26 return 0; 27 }
带佬的
总结:字母输出可以在每次小循环结束后,
将输出字母声明好,每轮小循环输出对应下标
不需要存储每轮读取,只需存最大值