是否有任何(与换行符相反)的字符? [英] Is there any (opposite of newline) char?

查看:106
本文介绍了是否有任何(与换行符相反)的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想知道我们是否可以从右到左,从下到上打印...当我试图编写一个程序来打印下面的正方形(对于输入'n',这里n = 4)时,我想到了这种想法

Was wondering if we could print from right to left, bottom to top... I got this thought when trying to write a program to print the following square (for an input 'n', here n=4 )

1  2  3  4
12 13 14 5
11 16 15 6 
10 9  8  7

这可以通过多种方式解决,方法是将其存储到2D数组中并打印该数组...(任何语言:Perl,C,C ++,Java).

This could be solved many ways, by storing into a 2D array and printing the array... (Any language: Perl, C, C++, Java).

推荐答案

长的答案是,您可以执行终端支持的任何操作.终端有很多种(或字符输出设备"),其中许多支持光标运动. (您可以查看 Termcap库项目来创建一个想象一下不同终端类型的功能.)有一个用于向上移动一行的终端命令,因此从本质上讲,您应该能够做到这一点.拨入 termcap数据库之后,我想到了以下内容:

The long answer is that you can do whatever the terminal supports. There are many kinds of terminals (or "character output devices"), many of them support cursor motions. (You can see the Termcap Library project to create a picture what different terminal types do.) There is a terminal command for moving up a line, so esentially yes, you should be able to do that. After poking in the termcap database, I came up with the following:

$ printf "\n"; printf '\e[A'; echo Foo
Foo

换句话说,\e[A字符串有一个不为零的机会让您排队.在某些终端上:)

In other words, the \e[A string has a non-zero chance to get you one line up. On some terminals :)

这篇关于是否有任何(与换行符相反)的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆