题解 | #将真分数分解为埃及分数#
将真分数分解为埃及分数
https://www.nowcoder.com/practice/e0480b2c6aa24bfba0935ffcca3ccb7b
#include <bits/stdc++.h>
using namespace std;
int main(){
string s = "";
while(cin >> s){
//法一
string res = "";
int idx = s.find('/');
string z = s.substr(0, idx);
string m = s.substr(idx + 1);
int n = stoi(z);
while(n--){
res += "1/" + m + "+";
}
res = res.substr(0, res.size() - 1);
cout << res << endl;
}
return 0;
}
华为题库题解 文章被收录于专栏
牛客华为题库的题解