题解 | #求小球落地5次后所经历的路程和第5次反弹的高度#
求小球落地5次后所经历的路程和第5次反弹的高度
https://www.nowcoder.com/practice/2f6f9339d151410583459847ecc98446?tpId=37&tqId=21261&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fdifficulty%3D3%26page%3D1%26pageSize%3D50%26search%3D%26tpId%3D37%26type%3D37&difficulty=3&judgeStatus=undefined&tags=&title=
#include <stdio.h> #include <string.h> void test(char *str) // 用于去除字符串最后后面的0 { int len = strlen(str); for (int i = len - 1; i > 0; i--) { if (str[i] == '0') { str[i] = '\0'; } else if (str[i] != '0') { return; } } } int main() { double n; scanf("%lf", &n); double total_S = 2 * n + n / 2 + n / 4 + n / 8; // 计算总路程 double end_H = n / 32; // 计算最后一次跳跃高度 char ret_S[10] = {'\0'}; char ret_H[10] = {'\0'}; sprintf(ret_S, "%.6f", total_S); // 转化结果为字符串 sprintf(ret_H, "%.6f", end_H); test(ret_S); test(ret_H); printf("%s\n", ret_S); printf("%s", ret_H); return 0; }