/* ㄏノ 0 繦诀计贺玻ネ 1,000,000  0  9 俱计 玻ネ计ぇ盢ㄤэ计じ (numeral character) 程硂﹃じぇ '\0' ﹃挡 (end-of-line) 才腹 ㄏㄤΘ 1,000,000 计﹃ (numeral string) ЧΘ˙艼祘Α絏 1. 盢案计 (even) 计じ簿埃 2. 块矪瞶计じ﹃ 3. 程 500 计じ﹃ 4. 璸衡块 3 计计じ计琌 '3' ㎝ '9' じ计 */ #include #include // ㄏノ跑计︽跑计 int main(void) { char digits[1000001]; // 皚盢纗 1000000 计﹃ (numeral string) char even_digits[6] = "02468"; // 案计计じ char odd_digits[6] = "13579"; // 计计じ char digit_3_9[3] = "39"; // 3 计计计じ char *ptr1, *ptr2; // ﹃夹 unsigned length; // ﹃ unsigned count_3_9[2]; // 3 计计じ计琌 '3' ㎝ '9' じ计 int i; // 癹伴跑计 srand(0); // ㄏノ 0 繦诀计贺 // 繦诀玻ネ 1000000  0  9 繦诀计盢ㄤ锣计じ (numeral character) for (i=0; i<1000000; i++) { digits[i]= (char)(rand() % 10) + 48; } digits[i] = '\0'; // ﹃挡 (end-of-string) 才腹 // 簿埃案计计じ ptr1 = digits; ptr2 = (char *) strpbrk(digits, odd_digits); while (ptr2!=NULL) { *ptr1 = *ptr2; ptr1++; ptr2 = (char *) strpbrk(ptr2+1, odd_digits); } *ptr1 = '\0'; // 块矪瞶计じ﹃ length = strlen(digits); printf(">>>> 计じ计 %d\n\n", length); // 块程 500 计じ printf(">>>> 程 500 计じ\n%s\n\n", digits+length-500); // 璸衡块 3 计计じ计琌 '3' ㎝ '9' じ计 ptr1 = (char *) strpbrk(digits, digit_3_9); for (i=0; i<2; i++) count_3_9[i] = 0; while (ptr1!=NULL) { switch (*ptr1) { case '3': {++count_3_9[0]; break;} case '9': {++count_3_9[1]; break;} } ptr1 = (char *) strpbrk(ptr1+1, digit_3_9); } printf(">>>> '3' ㎝ '9' じ计\n"); printf("じ \'3\' 计: %d\n", count_3_9[0]); printf("じ \'9\' 计: %d\n\n", count_3_9[1]); system("pause"); return(0); }