avatar
b*i
1
Divide number and return result in form of a string. e.g 100/3 result should
be 33.(3) Here 3 is in brackets because it gets repeated continuously and 5
/10 should be 0.5.
这题MIT300题里面也有,好像还满经典的,不知道怎么做,求解。
avatar
w*g
2
1b现在140仍然pending, 可以寄出485么,对批准时间有无影响?
avatar
b*i
3
我的想法大概是,每一个iteration保留被除数,商和余数。小数点以后把被除数放在
一个hashtable里
面,如果被除数出现过,就把上一次被除数到这一次被除数之间的商重复。

should
5

【在 b******i 的大作中提到】
: Divide number and return result in form of a string. e.g 100/3 result should
: be 33.(3) Here 3 is in brackets because it gets repeated continuously and 5
: /10 should be 0.5.
: 这题MIT300题里面也有,好像还满经典的,不知道怎么做,求解。

avatar
H*u
4
no, you need the approval notice of 140 to submit your 485
avatar
b*i
5
自己贴个code,test过几个好像是对的:
string number_division(int a, int b) {
int q, r;
string result;
// interger part
q = a / b;
r = a - b * q;
result.append(to_string(q));
// digital part
unordered_map m;
string digits;
int idx = 0;
while(r > 0) {
a = r * 10;
q = a / b;
r = a - b * q;
if(m.find(a) == m.end()) {
m[a] = idx;
digits.push_back(q + '0');
idx++;
} else {
int oldidx = m[a];
result.push_back('.');
result.append(digits.substr(0, oldidx));
result.push_back('(');
result.append(digits.substr(oldidx, idx-oldidx));
result.push_back(')');
break;
}
}
return result;
}

【在 b******i 的大作中提到】
: 我的想法大概是,每一个iteration保留被除数,商和余数。小数点以后把被除数放在
: 一个hashtable里
: 面,如果被除数出现过,就把上一次被除数到这一次被除数之间的商重复。
:
: should
: 5

avatar
c*8
6
yes, you can submit 485, but it will be denied if your 140 got denied.
avatar
w*a
7
这题最近出镜率贼高啊。
你这里5/10 返回0.5。有的面经让返回0.5(0)。我贴一个返回0.5(0)的吧。当然没啥区
别,细节改一下而已。
string get_decimal(int num, int den) {
string ret = to_string(num / den);
ret.push_back('.');
num %= den;
map rems;

while(num != 0 && !rems.count(num)) {
rems[num] = (int)ret.size();
num *= 10;
ret.push_back(num / den + '0');
num %= den;
}

if (num != 0) {
ret.insert(ret.begin() + rems[num], '(');
ret += ")";
} else {
ret += "(0)";
}
return ret;
}
avatar
M*1
8
非China or India nationality 可以交485,765,131....但140给拒了,所有申请都会
拒。
avatar
w*a
9
1337要是看板的话,建议加到leetcode里面。
我写了几个参考测试用例:
输入:
get_decimal(1, 6)
get_decimal(1, 3)
get_decimal(1, 2)
get_decimal(1, 8)
get_decimal(2, 3)
get_decimal(1, 9)
get_decimal(1, 11)
get_decimal(1, 17)
get_decimal(1, 19)
get_decimal(4, 9)
get_decimal(7, 12)
get_decimal(1, 81)
get_decimal(22, 7)
get_decimal(10, 5)
get_decimal(0, 5)
输出依次是
0.1(6)
0.(3)
0.5(0)
0.125(0)
0.(6)
0.(1)
0.(09)
0.(0588235294117647)
0.(052631578947368421)
0.(4)
0.58(3)
0.(012345679)
3.(142857)
2.(0)
0.(0)
avatar
w*0
10
EB1B的话,当然可以在140pending的时候递交485,那不然那么多人同时递交140和485
干嘛?这和EB2是不一样的...ls的回答都很莫名
当然如果最后140被拒了,485也就被拒了。很多人不着急的话,就等140批了再交485.
avatar
b*i
11
你这个写的很element,赞!

【在 w****a 的大作中提到】
: 这题最近出镜率贼高啊。
: 你这里5/10 返回0.5。有的面经让返回0.5(0)。我贴一个返回0.5(0)的吧。当然没啥区
: 别,细节改一下而已。
: string get_decimal(int num, int den) {
: string ret = to_string(num / den);
: ret.push_back('.');
: num %= den;
: map rems;
:
: while(num != 0 && !rems.count(num)) {

avatar
a*g
12
This is not true. LZ absolutely can submit 485 if the pending 140 is based
on eb1a or b. The upside is getting green card earlier if 140 got approved
and down side is losing money if 140 got denied.

【在 H******u 的大作中提到】
: no, you need the approval notice of 140 to submit your 485
avatar
S*s
13
A java version:
import java.util.HashSet;
import java.util.Set;
public class DecimalToString {
public static void main(String[] args) {
System.out.println(get_decimal(1, 6));
System.out.println(get_decimal(1, 3));
System.out.println(get_decimal(1, 2));
System.out.println(get_decimal(1, 8));
System.out.println(get_decimal(2, 3));
System.out.println(get_decimal(1, 9));
System.out.println(get_decimal(1, 11));
System.out.println(get_decimal(1, 17));
System.out.println(get_decimal(1, 19));
System.out.println(get_decimal(4, 9));
System.out.println(get_decimal(7, 12));
System.out.println(get_decimal(1, 81));
System.out.println(get_decimal(22, 7));
System.out.println(get_decimal(10, 5));
System.out.println(get_decimal(0, 5));
}
static String get_decimal(int num, int den) {
String ret = Integer.toString(num / den);
num %= den;
if (num == 0)
return ret + ".(0)";
ret = ret + ".";
Set set = new HashSet();
String temp = "";
while (num != 0 && !set.contains(num)) {
set.add(num);
num *= 10;
temp = temp + (num / den);
num = num % den;
}
if (num != 0) {
ret = ret + "(" + temp + ")";
} else {
ret = ret + temp;
}
return ret;
}
}
avatar
a*g
14
yes you can. It won't affect your current 140 process time. I submitted 485
about 20 days after eb1b 140, which was pending.

【在 w****g 的大作中提到】
: 1b现在140仍然pending, 可以寄出485么,对批准时间有无影响?
avatar
C*e
15
请问什么是MIT 300题?

should
5

【在 b******i 的大作中提到】
: Divide number and return result in form of a string. e.g 100/3 result should
: be 33.(3) Here 3 is in brackets because it gets repeated continuously and 5
: /10 should be 0.5.
: 这题MIT300题里面也有,好像还满经典的,不知道怎么做,求解。

avatar
W*n
16
ahongg (村支书) is right, you can with your own risk.
avatar
m*o
17
同问

【在 C********e 的大作中提到】
: 请问什么是MIT 300题?
:
: should
: 5

avatar
m*3
18
同问什么是MIT 300题
avatar
j*3
19
MIT300是什么!
avatar
w*a
20
MIT300是什么!!??
avatar
w*a
21
MIT300是什么!!??
avatar
w*a
22
MIT300是什么!!??
avatar
s*c
23
MIT300是什么!!??
楼下注意保持队形。。
avatar
b*i
24
额。。。都盖楼了
就是MIT板上以前的面经(2012之前的)
https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&cad=rja&uact
=8&ved=0CDAQFjAC&url=https%3A%2F%2Fbitbucket.org%2Flanbin%2Fmitbbs-iq%
2Fdownloads%2Fquestions-bf74e3c.pd&ei=foOPVKrpMYSyoQT-pILQDg&usg=
AFQjCNFhXur2-WMDwjVTm09uZiR0iQRxVQ&sig2=YOSJn2ZodHGo4sxIfJ7-og&bvm=bv.
82001339,d.cGU
看能打开不

【在 s***c 的大作中提到】
: MIT300是什么!!??
: 楼下注意保持队形。。

avatar
k*a
25
打不开

uact

【在 b******i 的大作中提到】
: 额。。。都盖楼了
: 就是MIT板上以前的面经(2012之前的)
: https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&cad=rja&uact
: =8&ved=0CDAQFjAC&url=https%3A%2F%2Fbitbucket.org%2Flanbin%2Fmitbbs-iq%
: 2Fdownloads%2Fquestions-bf74e3c.pd&ei=foOPVKrpMYSyoQT-pILQDg&usg=
: AFQjCNFhXur2-WMDwjVTm09uZiR0iQRxVQ&sig2=YOSJn2ZodHGo4sxIfJ7-og&bvm=bv.
: 82001339,d.cGU
: 看能打开不

avatar
y*e
26
这个括号开始的地方不是太对吧。。。
应该是循环部分开始,不应该是从小数点后面就开始了吧

【在 S********s 的大作中提到】
: A java version:
: import java.util.HashSet;
: import java.util.Set;
: public class DecimalToString {
: public static void main(String[] args) {
: System.out.println(get_decimal(1, 6));
: System.out.println(get_decimal(1, 3));
: System.out.println(get_decimal(1, 2));
: System.out.println(get_decimal(1, 8));
: System.out.println(get_decimal(2, 3));

avatar
c*w
27
请问哪里可以找到MIT300题

should
5

【在 b******i 的大作中提到】
: Divide number and return result in form of a string. e.g 100/3 result should
: be 33.(3) Here 3 is in brackets because it gets repeated continuously and 5
: /10 should be 0.5.
: 这题MIT300题里面也有,好像还满经典的,不知道怎么做,求解。

avatar
x*9
28

should
5
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define print(x) cout << x << endl
#define input(x) cin >> x
string make_result(const vector& vec, int idx) {
string res = "";
int len = vec.size();
for (int i = 0; i < idx; i++) {
res += to_string(vec[i]);
}
res += "(";
for (int i = idx; i < len; i++) {
res += to_string(vec[i]);
}
res += ")";
return res;
}
string to_frac(int a, int b) {
unordered_map mp;
vector vec;
int idx = 0;
while (true) {
if (mp.find(a) != mp.end()) {
return make_result(vec, mp[a]);
} else {
vec.push_back(a / b);
mp[a] = idx;
}
a = (a % b) * 10;
idx++;
}
}
int main () {
int a, b;
while (input(a >> b)) {
print(">> " << a << " " << b);
string int_part = to_string(a / b);
string fac_part = to_frac(a % b * 10, b);
print(int_part << '.' << fac_part);
}
return 0;
}

【在 b******i 的大作中提到】
: Divide number and return result in form of a string. e.g 100/3 result should
: be 33.(3) Here 3 is in brackets because it gets repeated continuously and 5
: /10 should be 0.5.
: 这题MIT300题里面也有,好像还满经典的,不知道怎么做,求解。

avatar
y*e
29
天。。。这题已经加入到leetcode里了,好激动啊,说明1337一直关注着新题,与时俱
进啊。
呼吁大神继续加题,leetcode继续保持oj里龙头的位置!
avatar
c*e
30
MIT 300 题哪里有?

should
5

【在 b******i 的大作中提到】
: Divide number and return result in form of a string. e.g 100/3 result should
: be 33.(3) Here 3 is in brackets because it gets repeated continuously and 5
: /10 should be 0.5.
: 这题MIT300题里面也有,好像还满经典的,不知道怎么做,求解。

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。