zoukankan      html  css  js  c++  java
  • c学习第7天

    约瑟夫环

     int people[ALL_NUM];
        int pos, people_num = ALL_NUM, step = 0;
        for (pos = 0; pos < ALL_NUM ;  pos++) {
            people[pos] = pos + 1;
        }
        pos = 0;
        while (people_num > 0)
        {
            if (people[pos]) {
                step++;
                
            }
            if (people[pos] && step == OUT_NUM) {
                printf("%d out 
    ", people[pos]);
                people[pos] = 0;
                people_num--;
            }
            pos++;
            if (pos == ALL_NUM) {
                pos = 0;
                
            }
            if (step == OUT_NUM) {
                step = 0;
            }
        }
        

    有一段文本,将文本中的所有单词,存放到一个字符串数组中

     

    int main ()
    {
        char (*str1)[50] = malloc(50*10);
        int last_index = 0;
        int current_index = 0;
        
        int count = 10;
        int word_num = 0;
        char *str =" main Hello World by on Copyright (c) 2013年 All rights reserved.";
        while (*(str+current_index++) ==' ') {
            
        }
        printf("current = %d
    ", current_index);
        last_index = current_index-1;
        do {
            if (*(str+current_index) == ' '||*(str+current_index) == '') {
                memcpy(str1[word_num], str+last_index, current_index-last_index);
                last_index = current_index;
                word_num++;
                if (word_num == count) {
                    count+=10;
                    str1 = realloc(str1, 50*count);
                }
            }
        }while (*(str+current_index++));
        
        for (int i = 0; i < word_num; i++) {
            printf("%s ", str1[i]);
        }
    
        return 0;
    }
  • 相关阅读:
    上传图片并压缩
    一张图教会你es6
    字符串生成二维码
    city-picker城市选择,三级联动
    jquery本地文件
    前端颜色选择器
    某音乐api
    js正则那些事
    Android判断网络是否打开,并打开设置网络界面
    execute、executeQuery和executeUpdate之间的区别 转
  • 原文地址:https://www.cnblogs.com/yinyakun/p/3394479.html
Copyright © 2011-2022 走看看