zoukankan      html  css  js  c++  java
  • 字符串逆序和统计数据中有多少位是1

    void invert(char *str,int len)
    {
     int i,j,n,temp;
     n=(len-1)/2;
     
     for(i=0;i<=n;i++)
     {
      j=len-1-i;
      
      temp=*(str+i);
      *(str+i)=*(str+j);
      *(str+j)=temp;
     }
     
    }

    int count(char *s,int len)
    {
     int i,j,cnt=0;
     for(j=0;j<len;j++)
     {
      for(i=0;i<8;i++)
      {
       if((*s&1)==1)
       {
        cnt++;
       }
       *s=*s>>1;
      }
      s++;
     }
     printf("cnt=%d /n",cnt);
     return cnt;
    }


    int main()
    {
     char array[]="happy life";
     char b[10]={3,3,3,11,1,1,1,1,1,1};
     int  countvalue=0;
     
     countvalue=count(b,sizeof(b));
     invert(array,sizeof(array));

    }

  • 相关阅读:
    移动布局---1. 移动端布局基础
    1. CSS新特性之选择器
    1. H5新增语义化标签
    POJ 3281
    poj 1986
    POJ 3728
    poj 2763
    poj 2749
    uva 11294
    LA 3713
  • 原文地址:https://www.cnblogs.com/LoongEmbedded/p/5298799.html
Copyright © 2011-2022 走看看