HackerRank说〜对stdout无反应〜Swift

时间:2019-01-23 18:21:13

标签: swift

我正在上一个有关Swift编程的动手实践课程,将我重定向到Hackerrank

编写一个名为printMessage的函数,该函数带有两个参数-字符串消息和整数计数。该消息应打印并按照count参数中指定的内容重复该消息。

消息:“你好,你好吗”

例如,以Count为8

这应该连续打印8条消息:“你好,你好”。

问题是当我提交我的代码时总是说错误答案,然后我尝试使用自定义输入,并且在STDOUT上没有响应。 有人知道怎么了吗?

import Foundation 

func printMessage(message: String, count: Int) {

    for _ in 0..<count {
        print(message)

    }
}

let message: String = readLine()!
let count: Int = Int(readLine()!)!
printMessage(message: message, count: count)

2 个答案:

答案 0 :(得分:2)

在一些快速练习中,Hackerrank会在缓冲区溢出时触发该消息,而不是警告您

答案 1 :(得分:1)

我以前遇到过这个问题,我解决它的方法是将代码保存在某个地方并重置为样板代码。因此,只需重置为样板并重新复制功能即可。在许多迅速的hackerrank问题上,它们具有以下内容:

SCC_STATE_PORT_7777_TCP_PORT=7777
KUBERNETES_SERVICE_PORT=443
PHP_PORT_9000_TCP_ADDR=10.35.246.141
SOCKETCLUSTER_SERVICE_PORT=8000
RDB_SERVICE_PORT_DB=28015
REDIS_SERVICE_PORT=6379
SCC_BROKER_PORT_8888_TCP_PROTO=tcp
MARIADB_PORT_3306_TCP=tcp://10.35.247.244:3306
KUBERNETES_PORT_443_TCP_PORT=443
RDB_SERVICE_PORT_WEB=8080
RDB_PORT=tcp://10.35.250.91:28015
RDB_PORT_28015_TCP=tcp://10.35.250.91:28015
KUBERNETES_SERVICE_HOST=10.35.240.1
NGINX_PORT_80_TCP_PORT=80
PHP_SERVICE_PORT=9000
RDB_SERVICE_PORT=28015
RDB_PORT_8080_TCP_ADDR=10.35.250.91
SCC_STATE_PORT_7777_TCP_ADDR=10.35.254.120
SOCKETCLUSTER_PORT=tcp://10.35.244.112:8000
RDB_PORT_28015_TCP_ADDR=10.35.250.91
PHP_PORT=tcp://10.35.246.141:9000
PHP_PORT_9000_TCP=tcp://10.35.246.141:9000
RDB_PORT_28015_TCP_PROTO=tcp
REDIS_PORT_6379_TCP_ADDR=10.35.254.59
MARIADB_PORT_3306_TCP_PORT=3306
SCC_STATE_PORT_7777_TCP_PROTO=tcp
MARIADB_SERVICE_PORT=3306
PHP_SERVICE_HOST=10.35.246.141
PHP_PORT_9000_TCP_PROTO=tcp
RDB_PORT_8080_TCP=tcp://10.35.250.91:8080
RDB_PORT_8080_TCP_PROTO=tcp
REDIS_PORT_6379_TCP_PROTO=tcp
MARIADB_PORT_3306_TCP_ADDR=10.35.247.244
KUBERNETES_PORT_443_TCP_ADDR=10.35.240.1
NGINX_PORT_80_TCP_ADDR=10.35.247.125
REDIS_SERVICE_HOST=10.35.254.59
SCC_BROKER_SERVICE_HOST=10.35.243.129
SCC_STATE_PORT_7777_TCP=tcp://10.35.254.120:7777
NGINX_PORT=tcp://10.35.247.125:80
SOCKETCLUSTER_PORT_8000_TCP_PROTO=tcp
SCC_STATE_SERVICE_PORT=7777
SCC_STATE_PORT=tcp://10.35.254.120:7777
NGINX_PORT_80_TCP_PROTO=tcp
SOCKETCLUSTER_PORT_8000_TCP=tcp://10.35.244.112:8000
RDB_SERVICE_HOST=10.35.250.91
NGINX_SERVICE_PORT_DB=80
MARIADB_PORT_3306_TCP_PROTO=tcp
PHP_PORT_9000_TCP_PORT=9000
SOCKETCLUSTER_PORT_8000_TCP_PORT=8000
SOCKETCLUSTER_PORT_8000_TCP_ADDR=10.35.244.112
REDIS_PORT_6379_TCP=tcp://10.35.254.59:6379
NGINX_PORT_80_TCP=tcp://10.35.247.125:80
SCC_BROKER_PORT_8888_TCP=tcp://10.35.243.129:8888
KUBERNETES_PORT=tcp://10.35.240.1:443
NGINX_SERVICE_PORT=80
RDB_PORT_28015_TCP_PORT=28015
RDB_PORT_8080_TCP_PORT=8080
SCC_BROKER_SERVICE_PORT=8888
SCC_STATE_SERVICE_HOST=10.35.254.120
MARIADB_SERVICE_HOST=10.35.247.244
KUBERNETES_SERVICE_PORT_HTTPS=443
REDIS_PORT=tcp://10.35.254.59:6379
REDIS_PORT_6379_TCP_PORT=6379
SCC_BROKER_PORT=tcp://10.35.243.129:8888
NGINX_SERVICE_HOST=10.35.247.125
SCC_BROKER_PORT_8888_TCP_PORT=8888
MARIADB_PORT=tcp://10.35.247.244:3306
KUBERNETES_PORT_443_TCP_PROTO=tcp
SOCKETCLUSTER_SERVICE_HOST=10.35.244.112
SCC_BROKER_PORT_8888_TCP_ADDR=10.35.243.129
KUBERNETES_PORT_443_TCP=tcp://10.35.240.1:443

函数后的代码是写到stdout的代码