In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.