Wednesday, October 21, 2015

UVa 10929 - You can say 11

// UVa 10929 - You can say 11

#include <string>
#include <iostream>
using namespace std;

int main() {
	string s;
	cin >> s;
	while (s.length() > 1 || s[0] != '0') {
		int sum = 0;
		int sign = -1;
		for (int i = 0; i < s.length(); i++) {
			sign *= -1;
			sum += sign * (s[i] - '0');
		}
		if (sum % 11 == 0)
			cout << s << " is a multiple of 11." << endl;
		else
			cout << s << " is not a multiple of 11." << endl;
		cin >> s;
	}
	return 0;
}

No comments:

Post a Comment