题解 | #包含数字9的数#
包含数字9的数
https://www.nowcoder.com/practice/0948f4f3344c452f843afd3585dd0f8d
//使用字符串查找函数解决这一问题
#include <stdio.h>
#include <string.h>
int main() {
int a = 0, count = 0;
char str[5];
char object[2] = {'9'};
while((a += 1) < 2020){
sprintf(str,"%d",a); //用sprintf把数字转换为字符串
if (strstr(str, object) != NULL){
count++;
}
}
printf("%d", count);
return 0;
}


查看9道真题和解析