Re: [閒聊] 每日leetcode

作者: Wardyal (Wardyal)   2024-08-23 16:07:39
※ 引述《dont (dont)》之銘言:
我寫了100多行
int find_same_char(string str);
void set_number_sets(number_set *ns, string str);
int calculate_gcd(int a, int b);
int calculate_lcm(int a, int b);
number_set calculate_fraction(number_set ns1, number_set ns2);
number_set fraction_reduction(number_set ns);
string get_number_set_output(number_set ns)
搞了7個子函式
=====
class Solution {
public:
string fractionAddition(string expression) {
stringstream ss(expression);
char op;
int a,b,c,d;
int num,den;
ss>>a;ss>>op;ss>>b; //extracting the 1st 2 numbers
while(ss>>c) //til we have the number
{
ss>>op; // op is the operator. which is '/' in our case
ss>>d;
num= a*d + b*c;
den= b*d;
a= num/__gcd(abs(num),abs(den));
b= den/__gcd(abs(num),abs(den));
}
c=__gcd(abs(a),abs(b));
a=a/c;
b=b/c;
return to_string(a)+'/'+to_string(b);
}
};
=====
結果看了一下解答
靠北 他怎麼20幾行就寫完了
還有ss又是什麼鬼 絲絲蛇嗎
作者: JIWP (JIWP)   2024-08-23 16:08:00
你怎麼也在leetcode了
作者: Wardyal (Wardyal)   2024-08-23 16:11:00
要那個了
作者: oin1104 (是oin的說)   2024-08-23 16:11:00
我好像寫100多行
作者: Wardyal (Wardyal)   2024-08-23 16:12:00
你好爛 然後我也是

Links booklink

Contact Us: admin [ a t ] ucptt.com