Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 62645dd

Browse files
solving old Contest
1 parent 7f348c2 commit 62645dd

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

‎once-in-a-tram.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
process.stdin.resume();
2+
process.stdin.setEncoding('ascii');
3+
4+
var input_stdin = "";
5+
var input_stdin_array = "";
6+
var input_currentline = 0;
7+
8+
process.stdin.on('data', function (data) {
9+
input_stdin += data;
10+
});
11+
12+
process.stdin.on('end', function () {
13+
input_stdin_array = input_stdin.split("\n");
14+
main();
15+
});
16+
17+
function readLine() {
18+
return input_stdin_array[input_currentline++];
19+
}
20+
21+
/////////////// ignore above this line ////////////////////
22+
23+
function pad(num, size) {
24+
var s = num+"";
25+
while (s.length < size) s = "0" + s;
26+
return s;
27+
}
28+
function onceInATram(x) {
29+
while(1) {
30+
let left = parseInt(x[0]) +parseInt(x[1])+parseInt(x[2]);
31+
for(let j=parseInt(x.slice(3,6))+1;j<1000;j++)
32+
{
33+
// console.log(j)
34+
let str = pad(j,3);
35+
let right = parseInt(str[0]) +parseInt(str[1])+parseInt(str[2]);
36+
// console.log(right)
37+
if(left === right)
38+
{
39+
return x.slice(0,3)+str;
40+
}
41+
}
42+
let nest = parseInt(x.slice(0,3))+1
43+
x = nest+"000";
44+
}
45+
}
46+
47+
function main() {
48+
var x = readLine();
49+
var result = onceInATram(x);
50+
process.stdout.write("" + result + "\n");
51+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /