0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cocolympic問題

Last updated at Posted at 2025-01-17

問題

cocolym.txtの内容を整形し以下の文字列のみを抽出する。

CoCoTo Happy 10th anniversary
Relationship
Think
Act
Check

step1

cocolym.txtから重複行を削除して下さい。

-----重複行を削除した出力例-----
'yrasrevinna ht01 yppaH oToCoC',
'shipRelation',
'T',
' h',
'  i',
'   n',
'    k',
'A.,.c  t',
'Aheaak'

Goal

文字列を以下のように整形してreturn answerTxtで結果を返して下さい。

CoCoTo Happy 10th anniversary
Relationship
Think
Act
Check

記載する箇所

「index.js」の★の部分に処理を記載してください。

module.exports = function (txt) {
    //(txt)に元データのcocolym.txt 2026行の文字列を読み込んでいます

  ★ここに重複行を削除、整形して文字列のみ出力する処理を記載する
  
    // return answerString
};

README.mdに従ってPR作成

※PRのマージはしないようにお願いします。
※PR時にbaseブランチを「cocolympic_pr_target」にしてください

禁止事項

こんなことはありえないと思いますが、回答の文字列を直接入力することは当然禁止です:frowning2:

module.exports = function (txt) {
    // 処理(txt = resource/cocolym.txt)
    const answerString = CoCoTo Happy 10th anniversary\nRelationship\nThink\nAct\nCheck
    return answerString
};

結果発表🥇🥈🥉

1位🥇

処理時間:0.12887 ms
コード12行

module.exports = function (txt) {
    // 処理(txt = resource/cocolym.txt)
    let answerString = [];
    const remove_str = '\n'+txt.substr(0,txt.indexOf(`\n`));
    const arr = txt.replaceAll(remove_str, '').split(/\n/);
    answerString[0] = arr[0].split("").reverse().join("");
    answerString[1] = arr[1].split(/(?=[A-Z])/).sort().join('').replace(/,/g, '');
    answerString[2] = arr.slice(2, 7).join('').replace(/\s+/g, '');
    answerString[3] = arr[7].replace(/[^a-zA-Z]/g, '');
    answerString[4] = arr[8].replace(/A/g, 'C').replace(/a/g, 'c');
    return answerString.join("\n");
};

2位🥈

処理時間:0.18899 ms
コード11行

module.exports = function (txt) {
    // 処理(txt = resource/cocolym.txt)
    let answerString = "";
    const tempString = txt.split('\n').filter((x, i, self) => self.indexOf(x) === i);
    answerString += tempString[0].split('').reverse().join('') + '\n';
    answerString += tempString[1].split(/(?=[A-Z])/).reverse().join('').replace(/,/g, '') + '\n';
    answerString += tempString.slice(2, 7).join('').replace(/\s+/g, '') + '\n';
    answerString += tempString[7].replace(/[^a-zA-Z]/g, '') + '\n';
    answerString += tempString[8].replace(/A/g, 'C').replace(/a/g, 'c');
    return answerString
};

3位🥉

処理時間:0.19594 ms
コード10行

module.exports = function (txt) {
    // 処理(txt = resource/cocolym.txt)
    const tmp1 = txt.split(/\n/).filter((text, index, self) => self.indexOf(text) === index);
    let result = tmp1[0].split("").reverse().join("") + '\n'
      + tmp1[1].substr(4) + tmp1[1].substr(0, 4) + '\n'
      + tmp1.slice(2, 7).join('').replace(/\s+/g, '') + '\n'
      + tmp1[7].replace(/[\s,.]/g, '') + '\n'
      + tmp1[8].replace(/[A]/, 'C').replace(/[a]/, 'c');
    return result;
};
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?