2015年9月2日 星期三

UVA 10922 C++

要用C++ 11
用C++會compile error

#include<iostream>
#include<string>
//#include<vector>
using namespace std;
int main()
{
string input;
string s_num;
int number,times;
while (cin >> input)
{
if (input == "0")
break;
times = 0;
s_num = input;
while (true)
{
number = 0;
for (int i = 0; i < s_num.length(); i++)
number = number + (s_num[i] - 48);
if (number / 9 == 1)
{
times++;
cout << input << " is a multiple of 9 and has 9-degree "<<times<<"." << endl;
break;
}
else if (number % 9 == 0)
{
times++;
s_num.clear();
s_num = to_string(number);
}
else
{
cout << input <<" is not a multiple of 9."<< endl;
break;
}
}
}
return 0;
}


沒有留言:

張貼留言