pat1016:部分A+B

https://www.patest.cn/contests/pat-b-practise/1016

#include "stdio.h"
#include "math.h"

int main()
{
	int a, b, i, k, suma = 0, sumb = 0;
	char A[11], B[11];
	scanf("%s %d %s %d", A, &a, B, &b);
	for(i = 0, k = 0; '\0' != A[i]; ++i)
		if(a == A[i] - '0')
			++k;
	for(i = 0; i < k; ++i)
		suma += a * (int)pow(10, i);
	for(i = 0, k = 0; '\0' != B[i]; ++i)
		if(b == B[i] - '0')
			++k;
	for(i = 0; i < k; ++i)
		sumb += b * (int)pow(10, i);
	printf("%d\n", suma + sumb);

	return 0;
}


你可能感兴趣的:(c,pat)