Thursday, October 15, 2015

UVa 10922 - 2 the 9s

// UVa 10922 - 2 the 9s
#include <string>
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	string line;
	while (getline(cin, line) && (line.length() > 1 || (line.length() == 1 && line[0] != '0'))) {
		int sum = 0, degree = 1;
		for (int i = 0; i < line.length(); i++)
			sum += (line[i] - '0');
		while (sum > 9) {
			degree++;
			int b4 = sum;
			sum = 0;
			while (b4) {
				sum += b4 % 10;
				b4 /= 10;
			}
		}
		if (sum == 9)
			cout << line << " is a multiple of 9 and has 9-degree " << degree << ".\n";
		else
			cout << line << " is not a multiple of 9.\n";
	}
	return 0;
}

No comments:

Post a Comment