2
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?

More than 3 years have passed since last update.

02. 「パトカー」+「タクシー」=「パタトクカシーー」

Posted at

02. 「パトカー」+「タクシー」=「パタトクカシーー」

「パトカー」+「タクシー」の文字を先頭から交互に連結して文字列「パタトクカシーー」を得よ.

###Go

package main

import (
	"fmt"
	"strings"
)

func main()  {
	var p1 string = "パトカー";
	var p2 string = "タクシー";
	var result string;

	//	文字を配列にする
	p1s := strings.Split(p1,"");
	p2s := strings.Split(p2,"");

	//	配列数ループ(「パトカー」に合わせる。同じ文字数だから・・・)
	for i := range(p1s) {
		//	各文字を1文字づつ連結
		result += p1s[i] + p2s[i];
	}

	//	結果を表示
	fmt.Println(result);
}

###python

# -*- coding: utf-8 -*-
p1 = u"パトカー"
p2 = u"タクシー"
p1s = []
p2s = []

#   文字列を配列へ(「パトカー」に合わせる。同じ文字数だから・・・)
for i in range(len(p1)):
    p1s.append(p1[i])
    p2s.append(p2[i])

#   配列数ループ(「パトカー」に合わせる)
result = ""
for i in range(len(p1s)):
    # 各文字を1文字づつ連結
    result += p1s[i] + p2s[i]

#   結果を表示
print (result)

###Javascript

let p1 = "パトカー";
let p2 = "タクシー";
var result = "";

//	文字を配列にする
let p1s = p1.split("");
let p2s = p2.split("");

//	配列数ループ(「パトカー」に合わせる。同じ文字数だから・・・)
for (var i = 0; i < p1s.length; i++) {
    //	各文字を1文字づつ連結
    result += p1s[i] + p2s[i];
}

//	結果を表示
console.log(result);

まとめ

どれも、イマイチ感がすごい。
他の人のソースを覗いてみる。

トップ

2
0
6

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
2
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?