How to use python, php or c language to realize string flipping
This article mainly explains "how to use python, php or c language to achieve string flipping". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use python, php or c language to realize string flipping".
Original title:
Q: there is an a.txt file, which contains the following 1234569 abcABCabc requirements: awk is required to print out the following result 987654321 cbaCBAcba
A:
Shell: [root@vps tmp] # rev a.txt 9654321 cbaCBAcba
Perl: [root@vps tmp] # perl-nle 'print scalar reverse $_;' a.txt 9654321 cbaCBAcba
Awk: [root@vps tmp] # awk'{num=split ($0djinarr, ""); for (iMagnum [I]) {printf arr [I]; if (iMagnum 1) {printf "\ n"}} 'a.txt 9654321 cbaCBAcba
Php: [root@vps tmp] # php-r'$fp=fopen ("a.txt", "r"); while (! feof ($fp)) {echo strrev (fgets ($fp,999));} echo "\ n";; '9654321 cbaCBAcba
Sed: [root@vps tmp] # sed'/\ n cbaCBAcba / (.\)\ (.\)\ (. *\ n\) / &\ 2\ 1
Python: (one of the methods)
> arr='hello'
> > arr [::-1]
'olleh'
(method 2)
> str='hello'
> tmp= "
> > for s in reversed (str):
... Tmp+=s
...
> print tmp
Olleh
Reverse.h
# ifndef _ reverse_h
Int getLine (char s [], int limit)
Void reverse (char s [])
# endif
Int getLine (char s [], int limit)
{
Int c,i
For (I = 0; ireverse.c)
# include "stdio.h"
# include "/ Users/chenqing/tmp/reverse.h"
# define MAXLINE 1000
/ *
Reverse a string use c langusge
, /
Int main (void)
{
Int len
Char line [MAXLINE]
If ((len = getLine (line,MAXLINE)) > 0) {
Reverse (line)
Printf ("% s", line)
}
Return 0
}
Gcc reverse.c-o reverse
Qing:tmp chenqing$ echo "ChinaCache" |. / reverse
EhcaCanihC above is an example of using these implementations to implement string flipping under the terminal command line.
Thank you for your reading, the above is the content of "how to use python, php or c language to achieve string flipping". After the study of this article, I believe you have a deeper understanding of how to use python, php or c language to achieve string flipping, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!