博文

<数据结构>:137-3(2008-04-07 22:17:00)

摘要:/* 
  <数据结构>   Page: 137  exercise:3   description:
   编写一个函数insert_left,在线索二叉树中,插入一个新节点child,作为节点parent的左儿子.节点parent的左儿子指针变为节点child的左儿子指针
*/

void insert_right(tree_node *parent,tree_node *child)
{
    tree_node *temp;

    child->left = parent->left;
    child->right = parent;
    parent->left = child;
    child->left_thread = parent->left_thread;
    child->right_thread = true;
    parent->left_thread = false;

    if ( ! child->left_thread)
    {
        temp = insucc(child);
       &n......

阅读全文(2050) | 评论:0

不重叠地重复出现次数最多的子串(2008-03-23 13:45:00)

摘要:/*
P.S: 这是我第一次参加论坛组织的比赛,此题是第52次的题目,虽然没有什么效率,但值得庆幸的是我的程序最后还通过了两组测试数据

给出一个由小写字母组成的串s和一个不超过s的长度的正整数l,求s所有长度不小于l的字串中在s中不重叠地重复出现次数最多的子串。只要输出这个子串出现的次数就行了。 特别强调:子串不是子序列,必须是从s截出来连续的一段。s也是自身的子串。 例如 s = "abcabc", l = 3, 那么输出2,因为所求的子串是abc。 再例如 s = "ababa", l = 3, 那么输出1,长度不小于3的字串包括aba, bab, abab, baba, ababa。其中后面四个显然都只出现一次。前一个aba和后一个aba重叠了一个a,所以只能算不重叠地出现了一次。 实现接口 int solve(const char *s, int l); s和l意思如上。通过返回值返回答案。
*/
#include<stdio.h> int solve(const char *s, int l);
int main()
{
    char s[]="jfurhgyaopylhijknmbjhutyaopglhkyinjbaopfjguthfaopkbmvnchfaop";
    int l;
   // printf("enter characters\n");
   // scanf("%s",s);
    printf("enter l\n");
    scanf("%d",&l);
    printf("%d",solve(s,l));
    getchar();getchar();
    return 0;
} int solve(const char *s, int l)
{
    int max=1......

阅读全文(6420) | 评论:2

successive numeral (2008-03-23 13:34:00)

摘要:/*
output a successive numeral both sides the character '-' from lift to right
example :
input :
1,4,3-9,3,7-9#
1,3d-5# output:
1,4,3,4,5,6,7,8,9,3,7,8,9
illegal zhaoyg
2008.1.11
*/ #include <stdio.h>
#include <conio.h> int main()
{
 int flage=0,input,input_end,temp;
 int in[100][2]={0} , count=-1;  printf("add '#' as a end of input , and a sigle '#' to end\n");  int a=0;
 while( (flage=scanf("%d",&input))==1 && input!='#')
 {   in[++count][0]=input;   if ((temp=getchar())!=',' && temp!='-')
  {
   flage=0;
   break;
  }   if (temp=='-')
  {
   if(scanf("%d",&input_end)==1)
   {
    in[count][1]=input_end;     if ((temp=getchar())!=',' && temp!='#')// eat off ',' after int......

阅读全文(1892) | 评论:0

上阶梯(2008-03-23 13:33:00)

摘要:/*
上阶梯,你可以一个一个阶梯上,也可以两个两个地来,
也可以一个和二个间隔着上,甚至可以一次k个阶梯
问题是,上一个阶梯数为n,每步能上1至k个阶的话,
你有多少种方法走完它?

如 n = 5 , k = 2,可以
1,1,1,1,1
2,1,1,1
1,2,1,1
1,1,2,1
1,1,1,2
2,2,1
2,1,2
1,2,2
共8种

输入阶梯数n(1 <= n <= 30)和每步最大阶数k(1<=k<=n):
5 2
5 3

输出:
8
13

难度:Easy
*/
#include <stdio.h>
#include <conio.h>
#define MAX 300 int a[MAX];
int in_step,in_total;  //in_step为最大步长即每次最多跨几个台阶,in_total为台阶总数
int count=0;   //统计成功次数 void fun(int index)
{
 int sum=0;   for (int i=1;i<=in_step;i++)
 {
  a[a[0]]=i;   for (int j=1;j<=a[0];j++)
   sum+=a[j];   if (sum==in_total)
  {
   count++;
   a[a[0]--]=0;
 
   for (a[0];a[a[0]]==in_step;a[0]--)    //如果a[a[0]]已达到最大步长则清0
    a[a[0]]=0;  &nbs......

阅读全文(2419) | 评论:0

大兵站队(2008-03-23 13:31:00)

摘要:/*
问题描述
大兵们站成一行横队。排长发出命令:立正!向右看——齐!!
唰的一声,所有大兵都向右看。
由于大兵们的身高不全相同,向右看的时候就能看到比他矮的士兵的头了。
如果他右边有一个人大于等于他的身高,那么他就看不到那个人右边的人了。
假设总共n个士兵,第i个士兵看到ki个头,问S=k1+k2+k3+..+kn 输入
多组测试数据,第一行是n(1<=n<=1e5),第二行是n个数,表示k1,k2,....,kn,
kn范围在1到1e9 输出
对于每组数据要输出一行,包含S的值,测试数据保证s<2e9 样例输入
2
1 2
3
1 2 3
3
3 2 1
3
1 1 1
5
1 5 2 9 3 样例输出
1
3
2
2
6 提示
对于:
5
1 5 2 9 3
5看到1;2看到5;9看到1,5,2;3看到9; 难度:easy
*/
#include <stdio.h> int main()
{
 int n,a[ 100000];
 int MAX,k;
 long count;  while (scanf("%d",&n)!=EOF)
 {
  MAX=0;
  count=0;
  
  for (k=0;k<n;k++)
  {
   scanf("%d",&a[k ]);    if (k!=0)
   {
    if (a[ k]>a[ MAX])
    {
     MAX=k;
     ......

阅读全文(2298) | 评论:0

循环移位(2008-03-23 13:28:00)

摘要:/*
题目描述:
给你一个字符串"abcdefg",循环左移两位得到"cdefgab",
循环右移两位得到"fgabcde" 输入:
多组测试数据,每组一行,第一个是int范围内的整数n,
表示要右移的位数,如果n是负数则表示要左移。接着后面
是一个串长小于10000000的字符串。
最后遇到EOF标志的时候结束。 输出:
输出移位后的字符串 样例输入:
2 abcdefg
-2 abcdefg 样例输出:
fgabcde
cdefgab 难度:for beginner
*/ #include <stdio.h>
#include <string.h>
#define MAX 10000000 char ch[MAX];
char *point; int main()
{
    int n;     while (scanf("%d %s",&n,ch)!=EOF)
 {
  point=ch;
  //getchar();   if(n<0)
  {
     n=(-1*n)%strlen(ch);
     point+=n;
     printf("%s",point);
     *point='\0';
     printf("%s\n",ch);    
  }
  else
  {
     n=n%strlen(ch);
    
   ......

阅读全文(2493) | 评论:0

大数相乘(2008-03-23 13:27:00)

摘要:
#include<stdio.h>
#include<conio.h>
#define MAX 100000
int main()
{    long x,y;
 int p;
    int a[MAX];
    int b[MAX];
    int c[MAX];
    int sum[MAX] ;
    int len_a,len_b,i,j,temp,k;
   
 while(1)
 {
    
     for (int i=0;i<MAX;i++)
     {
          a[i]=0;
          b[i]=0;
          c[i]=0;
          sum[i]=0;
        }
          
        printf("请输入两个相乘的数,用*分隔\n");
        scan......

阅读全文(2221) | 评论:0

分类排序(2008-03-23 13:17:00)

摘要:/*
题目描述:
编写一个StrSort函数,要求声明为int StrSort(char str[]);
功能是把传入的str参数里的字符串ASCII大小进行升序排序,
排序后的结果保存回str中。要求是对数字、小写字母、
大写字母分别排序,其它符号位置不变,
并且原来是数字的位置排序后还得是数字,
原来是小写字母的排序后还得是小写字母 输入:
按参数传递,传递的字符串最大串长是1000000个字符 输出:
按参数返回,相应原字符串即可
函数执行成功则应当返回非0值 样例输入:
a5b4c3
!d@c#B$A% 样例输出:
a3b4c5
!c@d#A$B%
07.11.9  zhaoyg
*/ #include<stdio.h>
#include<conio.h>
#include <string.h>
#define M 20
int StrSort(char *);
int main()
{
 char input[]="dje873hf/*6-4*fsjd83%#KHDS6f8hkldfjs83*fdjdk238sdhj";  //gets(input);  StrSort(input);
 
 puts(input);  getch();
 
 return 0;
} int StrSort(char a[ ])
{
 int i,j,lengh;
 char temp;  for (lengh=0;a[lengh];lengh++)
  ;  //lengh--;
   for (i=0;i<lengh;i++)
  for (j=0;j<=lengh;j++)
   if (((a[i ]<='z' && a[i ]>='a')&......

阅读全文(2547) | 评论:0

大数阶乘(2008-03-23 13:15:00)

摘要:
//大数阶乘
// 07.4.27 #include<stdio.h>
#include<time.h> int main()
{
    double duration;     int a[100000]={0};
    int N,i,c=1,j;     a[1]=1;
    clock_t start, finish;     printf("大数阶乘,请输入一个数\n");
    scanf("%d",&N);
    start = clock();
    for (j=1;j<=N;j++)
    {
        for (i=1;i<=c;i++)
        {
            a[i]=a[i]*j;
        }         for (i=1;i<=c;i++) 
        {
            /*不能写成(i=c;i>0;i--)因为这样将漏掉低位的进位,
        ......

阅读全文(2220) | 评论:0

数字正方形(2008-03-19 23:18:00)

摘要:输出如下图形
3 3 3 3 3
3 2 2 2 3
3 2 1 2 3
3 2 2 2 3
3 3 3 3 3

最笨版:
//任意输入一个数,实现其正方形
#include <stdio.h>
#include <conio.h>
#include <time.h> int main ()
{ clock_t start, end;
    //while(1)
   // {
 int a=0,n,b;
 int i,j;
 int c[200][200] ;
 int s,h,q;
 
 printf("请输入一个整数\n");
 scanf("%d",&n);
    q=n;
    b=2*n-1;
    start = clock();  while (n>0)
 {
  for (i=a;i<b;i++)
  {
   for (j=a;j<b;j++)
    c[i][j]=n;
  }
  n--;
  a++;
  b--;
 }
 for (s=0;s<(2*q-1);s++)
 {
  for (h=0;h<(2*q-1);h++)
   printf("%2d",c[s][h]);
   printf("\n");
 }
//}
end = clock();
&nb......

阅读全文(2267) | 评论:0