首页 > 其他 > 详细

Aha code Two

时间:2015-12-10 19:02:13      阅读:164      评论:0      收藏:0      [点我收藏+]

1. 解密QQ号

a.解密算法
#include <stdio.h> int main(void) { int q[102] = {0,6,3,1,7,5,8,9,2,4}, head, tail; int i; //初始化队列 head = 1; tail = 10; //队列中已经有9个元素了,tail指向队尾的后一个位置 while(head < tail)//当队列不为空的时候执行循环 { //打印队首并将队首出队 printf("debug in here 1\n"); printf("%d ", q[head]); head++; //先将新队首的数添加到队尾 q[tail] = q[head]; tail++; //再将队首出队 head++; printf("tail=%d head=%d\n", tail, head); } getchar(); getchar(); return 0; }
终端输出:
debug in here 1
6 tail=11 head=3
debug in here 1
1 tail=12 head=5
debug in here 1
5 tail=13 head=7
debug in here 1
9 tail=14 head=9
debug in here 1
4 tail=15 head=11
debug in here 1
7 tail=16 head=13
debug in here 1
2 tail=17 head=15
debug in here 1
8 tail=18 head=17
debug in here 1
3 tail=19 head=19

 

b.解密算法(利用结构体)
#include <stdio.h> struct queue { int data[100];//队列的主体,用来存储内容 int head;//队首 int tail;//队尾 }; int main() { struct queue q; int i, n; //初始化队列 q.head=1; q.tail=1; printf("向队列插入待解密的数的个数是:\n"); scanf("%d", &n); printf("依次插入%d个数为:", n); for(i=1;i<=n;i++) { //依次向队列插入9个数 scanf("%d",&q.data[q.tail]); q.tail++; } printf("打印解密后的数为:"); while(q.head < q.tail) //当队列不为空的时候执行循环 { //打印队首并将队首出队 printf("%d ",q.data[q.head]); q.head++; //先将新队首的数添加到队尾 q.data[q.tail] = q.data[q.head]; q.tail++; //再将队首出队 q.head++; } getchar();getchar(); return 0; }
终端输出
向队列插入待解密的数的个数是:
5
依次插入5个数为:1 2 3 4 5
打印解密后的数为:1 3 5 4 2

 

2.

Aha code Two

原文:http://www.cnblogs.com/try-again/p/5036735.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!