perl、python、php、shell、sed、awk、cを利用して文字列の反転を実現します。

1267 ワード

原題:
Q.a.txtファイルがありますが、中身は下記のとおりです。123459 abcABCabcはawkを使って、次の結果をプリントアウトしてください。987654321 cbaCBAcba。
A:
shell  :[root@vpstmp]菗rev a.txt 9654321 cbaCB Acbaperl:[root@vpstmp;菗perl-nle‘print scalar reverse’a.txt 9654321 cbaCB Acbaawk:[root@vpstmp]萼awk'{num=split($0、arr、");for(i=numi>0iC){printf arr[i];if(i==1){printf'}'a.txt 9654321 cbaCB Acbaphp:[root@vpstmp;菗php-r'$fp=fopen("a.txt"r")while(feof($fp){echo strev}echo";9654321 cbaCB Acbased:[root@vpstmp"(/G;s/\(.\)/\2\1///////D;s//'a.txt 9654321 cbaCBAcba
python:(方法の一つ)
>>arr='hello'>>arr[:-1]‘olleh’
(方法二)
>>str='hello'>>tmp=">>for s in reversed(str):…tmp+=s...>print tmpolleh
reverse.h菷ifndef_reverse_.hint getline(char s[],int limit);void reverse(char s[]);endif
int getLine(char s[],int limit){ int c,i for(i=0;irevers.co.1荫include“stdio.h”芫include“/Users/chenqing/tmp/reverse.h” reverse a string use c langguse*/int main(void){ int len; char line[MAXLINE] if((len=getLine)>0){  reverse;  printf("%s",line); } return 0;
gcc reverse.c-o reverseQing:tmp chenqing$echo"ChinaCache"_./reversehcanihC上では、これらを利用して端末コマンドラインの下で文字列の反転を実現する例です。ハハ、実はperlが実現した方が快適です。