欣乐

The eagles are coming!

导航

临时代码保存

12模拟链表,约瑟夫环。。来自一个失败的题意理解。。

 

var
  a,b:array[0..10] of longint;
  n,i,t,k,j,p,m:longint;

begin
  //readln(n);
  n:=10;
  for i:=1 to n do a[i]:=i;
  for i:=1 to n-1 do b[i]:=i+1;
  b[n]:=1;
  m:=0;
  t:=n;  
  repeat
    for j:=1 to 3 do begin
      p:=t;
      t:=b[t];  
    end;  
    b[p]:=b[t];
    inc(m);
  until m=8;
  writeln(b[p]);
  t:=p;
  for k:=1 to 20 do begin
    write( a[t],' ' );
    t:=b[t]; //
  end;
end.
View Code

 

数组的STL快排:

 

 

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
  int i,a[10];
  srand((int)time(0));
  for(i=0;i<10;i++)
  {
    a[i]=rand()%30;
    cout<<a[i]<<" ";
  }
  cout<<endl;
  sort(a,a+10);
  for(i=0;i<10;i++)
    cout<<a[i]<<" ";
  cout<<endl;
  return 0;
}
View Code

 

 

 

复赛新模板:

 

 

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{  
  int i,j;
  //freopen("xxx.in", "r", stdin);
  //freopen("xxx.out", "w", stdout);
 
  //...
 
  //fclose(stdin); fclose(stdout);
  return 0;
}
View Code

 

 

 

 

 

 

 

 

22

posted on 2014-11-01 01:11  欣乐  阅读(185)  评论(0编辑  收藏  举报