Exercise: Rot13 Reader
- package main
- import (
- "io"
- "os"
- "strings"
- "fmt"
- )
- type rot13Reader struct {
- r io.Reader
- }
- func (rot13 rot13Reader)Read(p []byte) (n int, err error){
- n,err = rot13.r.Read(p)
- for i := ; i < len(p); i++ {
- if (p[i] >= 'A' && p[i] < 'N') || (p[i] >='a' && p[i] < 'n') {
- p[i] +=
- } else if (p[i] > 'M' && p[i] <= 'Z') || (p[i] > 'm' && p[i] <= 'z'){
- p[i] -=
- }
- }
- return
- }
- func main() {
- s := strings.NewReader(
- "Lbh penpxrq gur pbqr!")
- r := rot13Reader{s}
- fmt.Println(r)
- io.Copy(os.Stdout, &r)
- }
go官方教程的答案地址https://gist.github.com/zyxar/2317744
A common pattern is an io.Reader that wraps another io.Reader
, modifying the stream in some way.
For example, the gzip.NewReader function takes an io.Reader
(a stream of gzipped data) and returns a *gzip.Reader
that also implements io.Reader
(a stream of the decompressed data).
Implement a rot13Reader
that implements io.Reader
and reads from anio.Reader
, modifying the stream by applying the ROT13 substitution cipher to all alphabetical characters.
The rot13Reader
type is provided for you. Make it an io.Reader
by implementing its Read
method.
Exercise: Rot13 Reader的更多相关文章
- exercise.tour.go google的go官方教程答案
/* Exercise: Loops and Functions #43 */ package main import ( "fmt" "math" ) fun ...
- cs231n笔记 (一) 线性分类器
Liner classifier 线性分类器用作图像分类主要有两部分组成:一个是假设函数, 它是原始图像数据到类别的映射.另一个是损失函数,该方法可转化为一个最优化问题,在最优化过程中,将通过更新假设 ...
- Building a Non-blocking TCP server using OTP principles
转自:https://erlangcentral.org/wiki/index.php/Building_a_Non-blocking_TCP_server_using_OTP_principles ...
- 【cs231n】线性分类笔记
前言 首先声明,以下内容绝大部分转自知乎智能单元,他们将官方学习笔记进行了很专业的翻译,在此我会直接copy他们翻译的笔记,有些地方会用红字写自己的笔记,本文只是作为自己的学习笔记.本文内容官网链接: ...
- CS231n课程笔记翻译3:线性分类笔记
译者注:本文智能单元首发,译自斯坦福CS231n课程笔记Linear Classification Note,课程教师Andrej Karpathy授权翻译.本篇教程由杜客翻译完成,巩子嘉和堃堃进行校 ...
- 使用OTP原则构建一个非阻塞的TCP服务器
http://erlangcentral.org/wiki/index.php/Building_a_Non-blocking_TCP_server_using_OTP_principles CONT ...
- MIT6.828 Preemptive Multitasking(上)
Lab4 Preemptive Multitasking(上) PartA : 多处理器支持和协作多任务 在实验的这部分中,我们首先拓展jos使其运行在多处理器系统上,然后实现jos内核一些系统功能调 ...
- 18 A GIF decoder: an exercise in Go interfaces 一个GIF解码器:go语言接口训练
A GIF decoder: an exercise in Go interfaces 一个GIF解码器:go语言接口训练 25 May 2011 Introduction At the Googl ...
- Extending JMeter – Creating Custom Config Element – Property File Reader
JMeter is one of the best open source tools in the Test Automation Community. It comes with all the ...
随机推荐
- POJ3282+模拟
模拟题 /* 模拟 注意:相同一边的车有先后顺序! */ #include<stdio.h> #include<string.h> #include<stdlib.h&g ...
- linux ubuntu 11.04 samba 服务器设置
安装 SAMBA 组件 sudo apt-get install samba smbfs smbclient 配置相关参数 sudo gedit /etc/samba/smb.conf 文件中相关 ...
- Qt: qobject_cast<QPushButton*>(sender()) 简化信号与槽的编写
当你觉得写代码是一件重复性极高的工作时,这时你就应该考虑换个方式来实现了. 提高代码效率,减少代码量. 代码片: void Widget::onClicked() { QPushButton* but ...
- 屏蔽QQ聊天对话框中的广告
原文地址: 怎么在QQ聊天对话框中屏蔽广告_百度经验 http://jingyan.baidu.com/article/48a42057ca12c1a924250402.html QQ已经成为 ...
- 查看Vim的option变量的值
以t_Co变量为例,最好用 :echo &t_Co 也可以使用 :set t_Co?,但是漏打?的话就会设置,得不偿失 要想知道在哪里这个变量被设置的,用 :verbose set t_Co? ...
- 在C++中调用DLL中的函数
如何在C++中调用DLL中的函数 应用程序使用DLL可以采用两种方式:一种是隐式链接,另一种是显式链接.在使用DLL之前首先要知道DLL中函数的结构信息.Visual C++6.0在VC\bin目录下 ...
- 【POJ】2104 K-th Number
区间第K大数.主席树可解. /* 2104 */ #include <iostream> #include <sstream> #include <string> ...
- No Hibernate Session bound to thread, and configuration does not allow
今天晚上挺悲催的,遇到了这个问题花费我很长时间,现在总结如下: 到这这种情况的发生有两种情况: 1,没有配置事物只要在Spring配置文件中添加如下代码: <bean id="txMa ...
- mysql隔离机制
转 MySQL隔离级别 mysql-Innodb事务隔离级别-repeatable read详解(转)
- entity framework 查询
1.简单查询: SQL: SELECT * FROM [Clients] WHERE Type=1 AND Deleted=0 ORDER BY ID EF: //Func形式 var clients ...