要用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;
}
2015年9月2日 星期三
UVA 591 C++
爛東西,為啥最後要endl 兩次才會過...
#include<iostream>
//#include<string>
#include<vector>
using namespace std;
int main()
{
vector<int> h;
int n, mid, total,move,times;
times = 1;
while (true)
{
total = 0;
move = 0;
cin >> n;
if (n == 0)
break;
h.resize(n);
for (int i = 0; i < n; i++)
{
cin >> h[i];
total = total + h[i];
}
mid = total / n;
for (int i = 0; i < n; i++)
{
if (h[i]>mid)
move = move + h[i] - mid;
}
cout << "Set #" << times << endl;
cout << "The minimum number of moves is " << move << "." << endl<<endl;
times++;
}
return 0;
}
#include<iostream>
//#include<string>
#include<vector>
using namespace std;
int main()
{
vector<int> h;
int n, mid, total,move,times;
times = 1;
while (true)
{
total = 0;
move = 0;
cin >> n;
if (n == 0)
break;
h.resize(n);
for (int i = 0; i < n; i++)
{
cin >> h[i];
total = total + h[i];
}
mid = total / n;
for (int i = 0; i < n; i++)
{
if (h[i]>mid)
move = move + h[i] - mid;
}
cout << "Set #" << times << endl;
cout << "The minimum number of moves is " << move << "." << endl<<endl;
times++;
}
return 0;
}
無聊打發時間 UVA 1585 C++
#include<iostream>
#include<string>
using namespace std;
int main()
{
int times,answer,tmp;
string input;
cin >> times;
for (int i = 0; i < times; i++)
{
answer = 0;
tmp = 0;
cin >> input;
for (int j = 0; j < input.length(); j++)
{
if (input[j] == 'X')
tmp = 0;
else
{
tmp = tmp + 1;
answer = answer + tmp;
}
}
cout << answer << endl;
}
return 0;
}
#include<string>
using namespace std;
int main()
{
int times,answer,tmp;
string input;
cin >> times;
for (int i = 0; i < times; i++)
{
answer = 0;
tmp = 0;
cin >> input;
for (int j = 0; j < input.length(); j++)
{
if (input[j] == 'X')
tmp = 0;
else
{
tmp = tmp + 1;
answer = answer + tmp;
}
}
cout << answer << endl;
}
return 0;
}
訂閱:
文章 (Atom)