JonsenElizee

Software Developing Blog

"An idea is fragile . It can be killed by a scornful smile or a yawn .It can be mound down by irony and scared to death by a cold look."
"Most cultures throughout human history have not liked creative individuals .They ignore them or kill them.It is a very efficient way of stopping creativity."

------Advertising boss Charles Browe and Howard Gardner ,professor at Harvard

   :: 首页 :: 新随笔 ::  ::  :: 管理 ::

  1 #include <stdio.h>
  2 #include <string.h>
  3
  4 int main()
  5 {
  6         char input[] = "ABCDEFGHIJklmnopqrstuvwxyz";
  7         char* str = input;
  8         int len = strlen(str);
  9         int i = 10; //move i characters to the end of the string str.
 10         int index = 0;
 11         while(index < i/2) {
 12                 printf("%c ==> %c\n", str[index], str[i-index-1]);
 13                 str[index] ^= str[i-index-1];
 14                 str[i-index-1] ^= str[index];
 15                 str[index] ^= str[i-index-1];
 16                 index ++;
 17         }
 18
 19         index = 0;
 20         while(index < (len-i)/2) {
 21                 printf("%c ==> %c\n", str[i+index], str[len-index-1]);
 22                 str[i+index] ^= str[len-index-1];
 23                 str[len-index-1] ^= str[i+index];
 24                 str[i+index] ^= str[len-index-1];
 25                 index ++;
 26         }
 27
 28         index = 0;
 29         while(index < len/2) {
 30                 printf("%c ==> %c\n", str[index], str[len-index-1]);
 31                 str[index] ^= str[len-index-1];
 32                 str[len-index-1] ^= str[index];
 33                 str[index] ^= str[len-index-1];
 34                 index ++;
 35         }
 36
 37         puts(str);
 38         return 0;
 39 }

Output
[root@localhost tmp]# gcc reverse.c && time a.out
A ==> J
B ==> I
C ==> H
D ==> G
E ==> F
k ==> z
l ==> y
m ==> x
n ==> w
o ==> v
p ==> u
q ==> t
r ==> s
J ==> k
I ==> l
H ==> m
G ==> n
F ==> o
E ==> p
D ==> q
C ==> r
B ==> s
A ==> t
z ==> u
y ==> v
x ==> w
klmnopqrstuvwxyzABCDEFGHIJ

real    0m0.001s
user    0m0.001s
sys     0m0.001s
[root@localhost tmp]#



posted on 2010-09-18 14:04 JonsenElizee 阅读(1166) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理


By JonsenElizee