0
1

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 5 years have passed since last update.

00. 文字列の逆順

Last updated at Posted at 2019-11-27

00.文字列の逆順

文字列"stressed"の文字を逆に(末尾から先頭に向かって)並べた文字列を得よ.

###Go

package main

import_ "fmt"

func main() {
	var data string = "stressed"
	var reverse string

	// 1.ループ
	for i := len(data) - 1; i >= 0; i-- {
		reverse += string(data[i])
	}

	fmt.Println(reverse)
}

###python


# -*- coding: utf-8 -*-
data = "stressed"
reverse = ""

#   1.逆カウントのループ
i = len(data) - 1
while i >= 0:
    reverse += data[i]
    i-=1
print(reverse)

#   2.range->reversed
reverse = ""
for i in reversed(range(len(data))):
    reverse += data[i]
print(reverse)

#   3.reversed->join
print(''.join(reversed(data)))

#   4.スライス
print(data[::-1])

###Javascript

var data = "stressed";
var reverse = ""

//  1.逆カウントのループ
for (var i = data.length - 1; i >= 0; i--) {
    reverse += data[i];
}
console.log(reverse);

//  2.split->reverse->join
console.debug(data.split("").reverse().join(""));

まとめ

goは日本語非対応。
問題ページとトップページ分割。

トップ

0
1
7

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?