p2020
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n;
while (cin >> n, n)
{
int a[n];
for (int i = 0; i < n; i ++)
cin >> a[i];
for (int i = 0; i < n - 1; i ++)
{
for (int j = i; j < n; j ++)
{
if (abs(a[i]) < abs(a[j]))
swap(a[i], a[j]);
}
}
for (int i = 0; i < n; i ++)
{
if (i == n - 1)
cout << a[i];
else
cout << a[i] << ' ';
}
cout << endl;
}
return 0;
}
p2021
#include <iostream>
using namespace std;
int fun(int n)
{
int a[6] = {100, 50, 10, 5, 2, 1}, count = 0;
for (int i = 0; i < 6; i ++)
{
int m = n / a[i];
count += m;
n = n % a[i];
}
return count;
}
int main()
{
int n;
while (cin >> n, n)
{
int a[n];
for (int i = 0; i < n; i ++)
cin >> a[i];
int count = 0;
for (int i = 0; i < n; i ++)
count += fun(a[i]);
cout << count << endl;
}
return 0;
}
p2022
#include <bits/stdc++.h>
using namespace std;
int main()
{
int m, n;
while (cin >> m >> n)
{
int a[m][n], x = 0, y = 0;
for (int i = 0; i < m; i ++)
for (int j = 0; j < n; j ++)
cin >> a[i][j];
int max = a[0][0];
for (int i = 0; i < m; i ++)
{
for (int j = 0; j < n; j ++)
{
if (abs(a[i][j]) > max)
{
x = i;
y = j;
max = abs(a[i][j]);
}
}
}
cout << x + 1 << ' ' << y + 1 << ' ' << a[x][y] << endl;
}
return 0;
}
p2023
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n, m;
while (cin >> n >> m)
{
int a[n][m];
for (int i = 0; i < n; i ++)
for (int j =0; j < m; j ++)
cin >> a[i][j];
double grade[n];
for (int i = 0; i < n; i ++)
{
double sum = 0;
for (int j = 0; j < m; j ++)
{
sum += a[i][j];
}
sum /= m;
grade[i] = sum;
if (i == n - 1) printf("%.2lf", grade[i]);
else printf("%.2lf ", grade[i]);
}
cout << endl;
double gpa[m];
for (int j = 0; j < m; j ++)
{
double sum = 0;
for (int i = 0; i < n; i ++)
{
sum += a[i][j];
}
sum /= n;
gpa[j] = sum;
if (j == m - 1) printf("%.2lf", gpa[j]);
else printf("%.2lf ", gpa[j]);
}
cout << endl;
int count = 0, flag;
for (int i = 0; i < n; i ++)
{
flag = 1;
for (int j = 0; j < m; j ++)
{
if (a[i][j] < gpa[j])
flag = 0;
}
if (flag == 1)
count ++;
}
cout << count << endl << endl;
}
return 0;
}
p2024
#include <iostream>
using namespace std;
bool legal(string s) {
if (isdigit(s[0])) return false;
for (int i = 0; i < s.size(); i++) {
if (!isalnum(s[i]) && s[i] != '_') return false;
}
return true;
}
int main() {
int t; cin >> t;
getchar();
while (t--) {
string s;
getline(cin, s);
if (legal(s)) cout << "yes" << endl;
else cout << "no" << endl;
}
return 0;
}
p2025
#include <iostream>
using namespace std;
int main()
{
string str;
while(cin >> str)
{
char max = 'A';
for (int i = 0; i < str.size(); i ++)
{
if (str[i] > max) max = str[i];
}
for (int i = 0; i < str.size(); i ++)
{
if (str[i] == max)
cout << str[i] << "(max)";
else
cout << str[i];
}
cout << endl;
}
return 0;
}
p2026
#include <iostream>
using namespace std;
int main()
{
string str;
while (getline(cin, str))
{
str[0] = str[0] - ('a' - 'A');
for (int i = 1; i < str.size(); i ++)
{
if (str[i] == ' ')
str[i + 1] = str[i + 1] - ('a' - 'A');
}
cout << str << endl;
}
return 0;
}
p2027
#include <iostream>
#include <cstdio>
using namespace std;
int words[5] = {1, 5, 9, 15, 21};
int main()
{
int n;
string str;
cin >> n;
getchar();
while (n --)
{
int count[26] = {0};
getline(cin, str);
for (int i = 0; i < str.size(); i ++)
{
if (str[i] != ' ')
count[str[i] - 'a'] ++;
}
for (int i = 0; i < 5; i ++)
{
printf("%c:%d\n", words[i] + 'a' - 1, count[words[i] - 1]);
}
if (n != 0) cout << endl;
}
return 0;
}
p2028
#include <iostream>
#include <cstdio>
using namespace std;
int fun(int x, int y)
{
int max = x;
if (max < y) max = y;
int num = max, i;
for (i = max;; i ++)
{
if (i % x == 0 && i % y == 0)
{
num = i;
break;
}
}
return num;
}
int main()
{
int n;
while (cin >> n)
{
int a[n];
for (int i = 0; i < n; i ++)
cin >> a[i];
int num = fun(a[0], a[1]);
for (int i = 2; i < n; i ++)
num = fun(num, a[i]);
cout << num << endl;
}
return 0;
}
p2029
#include <iostream>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
string str[n];
for (int i = 0; i < n; i ++)
cin >> str[i];
for (int i = 0; i < n; i ++)
{
int flag = 1;
for (int j = 0; j < str[i].size(); j ++)
{
if (str[i][j] != str[i][str[i].size() - j - 1])
flag = 0;
}
if (flag)
cout << "yes" << endl;
else
cout << "no" << endl;
}
}
return 0;
}
p2030
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
getchar();
while (n --)
{
string str;
int count = 0;
getline(cin, str);
for (int i = 0; i < str.size(); i ++)
{
if (str[i] < 0)
count ++;
}
cout << count / 2 << endl;
}
return 0;
}
p2031
#include <iostream>
#include <cstdio>
using namespace std;
string str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main()
{
int n, r, m;
while (cin >> n >> r)
{
if (n < 0)
{
cout << '-';
n = -n;
}
string a;
while (n != 0)
{
m = n % r;
a += str[m];
n /= r;
}
for (int i = a.size() - 1; i >= 0; i --)
cout << a[i];
cout << endl;
}
return 0;
}
p2032
#include <iostream>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
int a[n][n];
for (int j = 0; j < n; j ++)
{
for (int k = 0; k < j + 1; k ++)
{
if (k == 0 || k == j) a[j][k] = 1;
else a[j][k] = a[j-1][k] + a[j-1][k-1];
}
}
for (int j = 0; j < n; j ++)
{
for (int k = 0; k < j + 1; k ++)
{
if (k == j) cout << a[j][k];
else cout << a[j][k] << ' ';
}
cout << endl;
}
cout << endl;
}
return 0;
}
p2033
#include <iostream>
using namespace std;
int main()
{
int n;
int ah, am, as, bh, bm, bs;
cin >> n;
while(n --)
{
cin >> ah >> am >> as >> bh >> bm >> bs;
int t = (ah + bh)*3600 + (am + bm)*60 + as + bs;
cout << t/3600 << ' ' << t / 60 % 60 << ' ' << t % 60 << endl;
}
return 0;
}
p2034
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n, m;
while (cin >> n >> m, (n || m))
{
int a[n], b[m];
for (int i = 0; i < n; i ++)
cin >> a[i];
for (int i = 0; i < m; i ++)
cin >> b[i];
sort(a, a + n);
sort(b, b + m);
int book[n][2];
for (int i = 0; i < n; i ++)
{
book[i][0] = a[i];
book[i][1] = 0;
}
for (int i = 0; i < n; i ++)
{
for (int j = 0; j < m; j ++)
{
if (a[i] == b[j])
{
book[i][1] = 1;
}
}
}
int count = 0;
for (int i = 0; i < n; i ++)
{
if (book[i][1] == 0)
{
cout << book[i][0] << ' ';
count ++;
}
}
if (count == 0) cout << "NULL" << endl;
else cout << endl;
}
return 0;
}
p2035
#include <iostream>
using namespace std;
int main()
{
int a, b;
while (cin >> a >> b, (a || b))
{
int m = 1;
for (int i = 0; i < b; i ++)
{
m *= a;
while (m > 1000)
m %= 1000;
}
cout << m << endl;
}
return 0;
}
p2036
#include <iostream>
using namespace std;
struct point {
int x, y;
}p[105];
int main() {
int n;
while (cin >> n, n) {
for (int i = 0; i < n; i++) {
cin >> p[i].x >> p[i].y;
}
p[n].x = p[0].x, p[n].y = p[0].y;
int area = 0;
for (int i = 0; i < n; i++) {
area += (p[i].x * p[i + 1].y - p[i].y * p[i + 1].x);
}
printf("%.1lf\n", area / (double)2);
}
return 0;
}
p2037
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct node
{
int beg;
int end;
};
bool cmp(struct node m, struct node n)
{
return m.end < n.end;
}
int main()
{
int n;
while (cin >> n, n)
{
struct node program[n];
for (int i = 0; i < n; i ++)
cin >> program[i].beg >> program[i].end;
sort(program, program + n, cmp);
int last = program[0].end;
int cnt = 1;
for (int i = 1; i < n; i ++)
{
if (program[i].beg >= last)
{
last = program[i].end;
cnt ++;
}
}
cout << cnt << endl;
}
return 0;
}