class Solution { public: /** * 返回一个严格四舍五入保留两位小数的字符串 * @param n int整型 n * @return string字符串 */ string Probability(int n) { // write code here double gl=0.5; double t=pow(gl,n)*2; //putchar('"'); int ans=t*1000; //printf("%d.%d%d",ans/1000,ans/100%10,ans/10%10+(ans%10>4)); //putchar('"'); string s; //s+='"'; if(ans/1000)s+='1'; else s+='0'; s+='.'; s+='0'+ans/100%10; s+='0'+ans/10%10+(ans%10>4); //s+='"'; return s; } };
全部评论
(0) 回帖