1011. A+B和C (15)
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
long long a, b, c;
cin >> a >> b >> c;
cout << "Case #" << i + 1 << ": ";
if (a > 0 && b > 0 && c < 0)
cout << "true" << endl;
else if (a < 0 && b < 0 && c > 0)
cout << "false" << endl;
else
{
if (a + b > c)
cout << "true" << endl;
else
cout << "false" << endl;
}
}
return 0;
}
1012. 数字分类 (20)
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
bool flag[5];
for (int i = 0; i < 5; i++)
flag[i] = false;
int sum0 = 0;
int fg = 1;
int sum1 = 0;
int count = 0;
int remain3 = 0, cnt3 = 0;
int maxremain4 = 0;
for (int i = 0; i < n; i++)
{
int tmp;
cin >> tmp;
if (tmp % 10 == 0)
{
flag[0] = true;
sum0 += tmp;
}
else if (tmp % 5 == 1)
{
flag[1] = true;
sum1 += fg * tmp;
fg *= -1;
}
else if (tmp % 5 == 2)
{
flag[2] = true;
count++;
}
else if (tmp % 5 == 3)
{
flag[3] = true;
cnt3++;
remain3 += tmp;
}
else if (tmp % 5 == 4)
{
flag[4] = true;
if (tmp > maxremain4)
maxremain4 = tmp;
}
}
if (flag[0])
cout << sum0 << " ";
else
cout << "N ";
if (flag[1])
cout << sum1 << " ";
else
cout << "N ";
if (flag[2])
cout << count << " ";
else
cout << "N ";
if (flag[3])
printf("%.1f ", remain3 * 1.0 / cnt3);
else
cout << "N ";
if (flag[4])
cout << maxremain4 << endl;
else
cout << "N" << endl;
return 0;
}
1013. 数素数 (20)
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
using namespace std;
const int MAX = 105000;
bool prime[MAX];
void init()
{
memset(prime, true, sizeof(prime));
for (int i = 2; i <= MAX >> 1; i++)
{
for (int j = i << 1; j < MAX; j += i)
prime[j] = false;
}
}
vector<int> primes;
int main()
{
init();
primes.push_back(0);
for (int i = 2; i < MAX; i++)
{
if (prime[i])
primes.push_back(i);
}
int M, N;
cin >> M >> N;
int lines = (N - M) / 10 + 1;
int index = M;
if (lines == 1)
{
cout << primes[index++];
int space = N - M;
while (space--)
cout << " " << primes[index++];
cout << endl;
}
else
{
for (int i = 1; i < lines; i++)
{
for (int j = 0; j < 9; j++)
cout << primes[index++] << " ";
cout << primes[index++] << endl;
}
while (index < N)
cout << primes[index++] << " ";
cout << primes[N] << endl;
}
return 0;
}
1014. 福尔摩斯的约会 (20)
同PAT-A-1061.Dating (20)见:
http://blog.csdn.net/hale1007/article/details/20460423