全WA找不出错
查看原帖
全WA找不出错
1054137
EkSulfur楼主2023/12/1 16:16

救救

#include <stdio.h>
#include <string.h>
#include <math.h>

void itoa(int x, char *a) {
	int n = 0;
	int y = x;
	while (y != 0) {
		n++;
		y /= 10;
	}
	for (int i = 0; i < n; i++) {
		a[i] = (char)((x / pow(10, n - i - 1)) + (int)'0');
		x = x % (int)pow(10, n - i - 1);
	}
}

int main(void) {
	int n, ct, l = 0;
	char t;
	scanf("%d %c", &n, &t);
	int m = n;
	while (m != 0) {
		l++;
		m /= 10;
	}
	char s[l + 1];
	for (int i = 0; i <= n; i++) {
		itoa(i, s);
		for (int j = 0; j < (int)strlen(s); j++) {
			if (s[j] == t) {
				ct++;
			}
		}
	}
	printf("%d", ct);
	return 0;
}
2023/12/1 16:16
加载中...