pat1017:A除以B

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

#include "stdio.h"
#include "string.h"

int main()
{
	int b, i, temp = 0, flag = 0;
	char a[1001];
	scanf("%s %d", a, &b);
	for(i = 0; i < strlen(a); ++i)
	{
		temp = temp * 10 + a[i] - '0';
		if(temp >= b)
		{
			printf("%c", temp / b + '0');
			flag = 1;
		}
		else if(flag)
			printf("%c", '0');
		temp = temp % b;
	}
	if(0 == flag)
		printf("0 %s\n", a);
	else
		printf(" %d\n", temp);

	return 0;
}


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