C:3-1

/*   binsearch函数:在v[0]<=v[1]<=v[2]<'''<=v[n-1]中查找X   */

int binsearch(intx,int v[],int n)

{

      int low,high,mid;

     

      low=0;

      high=n-1;

      while(low<high){

           mid=(low+high)/2;

           if(x<v[mid])

             high=mid-1;

        else if(x>v[mid])

          low=mid+1;

        else  //找到了匹配的值

           return mid

      }

      return -1// 没有找到匹配的值

}

 

 

#include<stdio.h>

main()      //统计数字、空白符及其他字符

{

      int c,i,nwhite,nother,ndigit[10];

    nwhite=nother=0;

    for(i=0;i<10;i++)

        ndigit[i]=0;

    while((c=getchar())!=EOF){

        switch(c){

              case '0':case'1':case'2':case'3':case'4':

                 case'5':case'6':case'7':case'8':case'9':

                     ndigit[c-'0']++;

                     break;

            case' ':case'/n':case'/t':

              nwhite++;

              break;

            default:

              nother++;

              break;

          }

    }

    printf("digits=");

    for(i=0;i<10;i++)

       printf(" %d",ndigit[i]);

    printf(",white space =%d,other =%d/n",nwhite,nother);

    return 0;        

}

 

 

/*escape:expand newline and tab into visible sequences*/

/*         while copying  the string t to s         */

void escape(char s[],char t[])

{

      int i,j;

      for(i=j=0;t[i]!='/0';i++)  //控制整个循环

         switch(t[i]){

       case '/n':          //newline

            s[j++]='//';   //j是目标字符串s的索引

            s[j++]='n';

            break;

       case '/t':          //tab

            s[j++]='//';

            s[j++]='t' ;

            break;

       default:           //all other  chars

            s[j++]=t[i];  // i是源字符串的索引

            break;

         }

   s[j]='/0';

}

 

 

/*unescape:convert escape sequences into real characters*/

/*     while copying the string t to s      */

void unescape(char s[],char t[])

{

      int i,j;

      for(i=j=0;t[i]!='/0';i++)

          if(t[i]!='//')

            s[j++]=t[i];

       else                //it  is  a  backslash

          switch(t[++i]){

              case 'n':     //real newline

                  s[j++]='/n'; ///n转化为换行符

                  break;

          case 't':        ///t转化为制表符

              s[j++]='/t' ;

              break;

            default:       //all other chars

                s[j++]='//';//把反斜杠后面的是其他字符的情况——

                s[j++]=t[i];//把反斜杠和t[i] 复制到字符串s中去

                break;

          }

       s[j]='/0';

 

/*unescape:convert escape sequences into real characters*/

/*     while copying the string t to s      */

void unescape(char s[],char t[])

{

      int i,j;

      for(i=j=0;t[i]!='/0';i++)

         switch(t[i]){

               case '//':        //it  is  a  backslash

          switch(t[++i]){    //switch嵌套

              case 'n':     //real newline

                  s[j++]='/n'; ///n转化为换行符

                  break;

          case 't':        ///t转化为制表符

              s[j++]='/t' ;

              break;

            default:       //all other chars

                s[j++]='//';//把反斜杠后面的是其他字符的情况——

                s[j++]=t[i];//把反斜杠和t[i] 复制到字符串s中去

                break;

          }

          break;

       default:

          s[j++]=t[i];

         break

       }

       s[j] ='/0';

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值