C语言PAT乙级试题答案1016

C语言PAT乙级试题答案1016_第1张图片
代码如下:

#include 

int main()
{
	char A[100]="\0", B[100]="\0";
	int x, y;
	int sum1 = 0, sum2 = 0;
	scanf("%s", A, sizeof(A));
	scanf("%d", &x);
	for (int i = 0; A[i] != '\0'; i++) {
		int t1 = A[i] - '0';
		if (t1 == x) {
			sum1 = sum1 * 10 + x;
		}
	}
	scanf("%s", B, sizeof(B));
	scanf("%d", &y);
	for (int j = 0; B[j] != '\0'; j++) {
		int t2 = B[j] - '0';
		if (t2 == y) {
			sum2 = sum2 * 10 + y;
		}
	}
	printf("%d", sum1 + sum2);
	return 0;
}

PS:把自己绕进数据类型的坑里去了,想了半天才想清楚(T.T)

你可能感兴趣的:(C语言PAT乙级试题答案1016)