约瑟夫环
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) == '