都是一些水题,就直接放代码了,有些解释在注释里。
其中有几题个人感觉不是很水,这里面就没放代码,题解我会另外写。
文章目录
- L1-001 Hello World (5 分)
- L1-002 打印沙漏 (20 分)
- L1-003 个位数统计 (15 分)
- L1-004 计算摄氏温度 (5 分)
- L1-005 考试座位号 (15 分)
- L1-006 连续因子 (20 分)
- L1-007 念数字 (10 分)
- L1-008 求整数段和 (10 分)
- L1-009 N个数求和 (20 分)
- L1-010 比较大小 (10 分)
- L1-011 A-B (20 分)
- L1-012 计算指数 (5 分)
- L1-013 计算阶乘和 (10 分)
- L1-014 简单题 (5 分)
- L1-015 跟奥巴马一起画方块 (15 分)
- L1-016 查验身份证 (15 分)
- L1-017 到底有多二 (15 分)
- L1-018 大笨钟 (10 分)
- L1-019 谁先倒 (15 分)
- L1-020 帅到没朋友 (20 分)
- L1-021 重要的话说三遍 (5 分)
- L1-022 奇偶分家 (10 分)
- L1-023 输出GPLT (20 分)
- L1-024 后天 (5 分)
- L1-025 正整数A+B (15 分)
- L1-026 I Love GPLT (5 分)
- L1-027 出租 (20 分)
- L1-028 判断素数 (10 分)
- L1-029 是不是太胖了 (5 分)
- L1-030 一帮一 (15 分)
- L1-031 到底是不是太胖了 (10 分)
- L1-032 Left-pad (20 分)
- L1-033 出生年 (15 分)
- L1-034 点赞 (20 分)
- L1-035 情人节 (15 分)
- L1-036 A乘以B (5 分)
- L1-037 A除以B (10 分)
- L1-038 新世界 (5 分)
- L1-039 古风排版 (20 分)
- L1-040 最佳情侣身高差 (10 分)
- L1-041 寻找250 (10 分)
- L1-042 日期格式化 (5 分)
- L1-043 阅览室 (20 分)
- L1-044 稳赢 (15 分)
- L1-045 宇宙无敌大招呼 (5 分)
- L1-047 装睡 (10 分)
- L1-048 矩阵A乘以B (15 分)
- L1-051 打折 (5 分)
- L1-052 2018我们要赢 (5 分)
- L1-053 电子汪 (10 分)
- L1-054 福到了 (15 分)
- L1-055 谁是赢家 (10 分)
- L1-056 猜数字 (20 分)
L1-001 Hello World (5 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 200010;
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
printf("Hello World!\n");
return 0;
}
L1-002 打印沙漏 (20 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 200010;
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, x = 0, num = 0, ans;
char s[5], c;
scanf("%d%s", &n, s);
c = s[0];
int nn = (n - 1) / 2;
while(1)
{
num = num + 3 + (2 * x);
if(num <= nn)
{
x++;
ans = num;
}
else
break;
}
ans = n - (ans * 2 + 1);
for(int i = 1; i <= x; i++)
{
for(int j = 1; j < i; j++)
printf(" ");
for(int j = 1; j <= 3 + 2 * (x - i); j++)
printf("%c", c);
printf("\n");
}
for(int i = 1; i <= x; i++)
printf(" ");
printf("%c\n", c);
for(int i = x; i >= 1; i--)
{
for(int j = i - 1; j >= 1; j--)
printf(" ");
for(int j = 3 + 2 * (x - i); j >= 1 ; j--)
printf("%c", c);
printf("\n");
}
printf("%d\n", ans);
return 0;
}
L1-003 个位数统计 (15 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 200010;
char s[1010];
int a[15];
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
scanf("%s", s);
int len = strlen(s);
for(int i = 0; i < len; i++)
{
a[s[i] - '0']++;
}
for(int i = 0; i < 10; i++)
{
if(a[i] != 0)
printf("%d:%d\n", i, a[i]);
}
return 0;
}
L1-004 计算摄氏温度 (5 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 200010;
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int F, C;
scanf("%d", &F);
C = 5 * (F - 32) / 9;
printf("Celsius = %d\n", C);
return 0;
}
L1-005 考试座位号 (15 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 100010;
ll gcd(ll a, ll b){return b==0?a:gcd(b,a%b);}
struct Node {
ll id;
int a, b;
}node[1010];
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, m;
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%lld%d%d", &node[i].id, &node[i].a, &node[i].b);
scanf("%d", &m);
while(m--)
{
int x;
scanf("%d", &x);
for(int i = 0; i < n; i++)
{
if(node[i].a == x)
{
printf("%lld %d\n", node[i].id, node[i].b);
break;
}
}
}
return 0;
}
L1-006 连续因子 (20 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 1010;
ll gcd(ll a, ll b){return b==0?a:gcd(b,a%b);}
bool isprime(int n)
{
if(n == 2 || n == 3)
return true;
if(n % 6 != 1 && n % 6 != 5)
return false;
int t = sqrt(n);
for(int i = 2; i <= t; i++)
{
if(n % i == 0 || n % (i + 2) == 0)
return false;
}
return true;
}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, sum, i, j, ans = 0, start, end;
scanf("%d", &n);
if(isprime(n))
{
printf("1\n%d\n", n);
return 0;
}
for(i = 2; i <= sqrt(n); i++)
{
if(n % i == 0)
{
sum = i;
for(j = i + 1; j <= sqrt(n); j++)
{
sum *= j;
if(n % sum != 0)
break;
}
if(ans < j - i)
{
ans = j - i;
start = i;
end = j;
}
}
}
printf("%d\n", ans);
for(i = start; i < end - 1; i++)
{
printf("%d*", i);
}
printf("%d\n", end - 1);
return 0;
}
L1-007 念数字 (10 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 1010;
ll gcd(ll a, ll b){return b==0?a:gcd(b,a%b);}
map<int, string> m;
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
m[0] = "ling";
m[1] = "yi";
m[2] = "er";
m[3] = "san";
m[4] = "si";
m[5] = "wu";
m[6] = "liu";
m[7] = "qi";
m[8] = "ba";
m[9] = "jiu";
string s;
cin >> s;
int len = s.length();
if(s[0] == '-')
cout << "fu";
else
cout << m[s[0] - '0'];
for(int i = 1; i < len; i++)
cout << ' ' << m[s[i] - '0'];
return 0;
}
L1-008 求整数段和 (10 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 1010;
ll gcd(ll a, ll b){return b==0?a:gcd(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int a, b, sum = 0, flag = 1;
scanf("%d%d", &a, &b);
for(int i = a; i <= b; i++)
{
printf("%5d", i);
sum += i;
flag++;
if(flag % 6 == 0)
{
flag = 1;
printf("\n");
}
}
if(flag != 1)
printf("\n");
printf("Sum = %d\n", sum);
return 0;
}
L1-009 N个数求和 (20 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 1010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ll n, a1, a2, b1, b2, gcd, lcm, ans = 0;
scanf("%lld", &n);
scanf("%lld/%lld", &a1, &b1);
for(int i = 1; i < n; i++)
{
scanf("%lld/%lld", &a2, &b2);
gcd = GCD(b1, b2);
lcm = b1 * b2 / gcd;
a1 = a1 * (lcm / b1);
a2 = a2 * (lcm / b2);
a1 = a1 + a2;
b1 = lcm;
gcd = GCD(fabs(a1), b1);
a1 = a1 / gcd;
b1 = b1 / gcd;
}
ans = a1 / b1;
a1 %= b1;
if(ans == 0)
{
if(a1 == 0)
printf("0\n");
else
printf("%lld/%lld\n", a1, b1);
}
else
{
if(a1 == 0)
printf("%lld\n", ans);
else
printf("%lld %lld/%lld\n", ans, a1, b1);
}
return 0;
}
L1-010 比较大小 (10 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 1010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int a[3];
scanf("%d%d%d", &a[0], &a[1], &a[2]);
sort(a, a + 3);
printf("%d->%d->%d\n", a[0], a[1], a[2]);
return 0;
}
L1-011 A-B (20 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
char s1[maxn], s2[maxn];
int len = 0;
char c;
vector<char> v;
vector<char>::iterator it;
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
while(1)
{
scanf("%c", &c);
if(c == '\n')
break;
s1[len++] = c;
}
len = 0;
while(1)
{
scanf("%c", &c);
if(c == '\n')
break;
s2[len++] = c;
}
for(int i = 0; i < len; i++)
v.push_back(s2[i]);
len = strlen(s1);
for(int i = 0; i < len; i++)
{
it = find(v.begin(), v.end(), s1[i]);
if(it == v.end())
printf("%c", s1[i]);
}
return 0;
}
L1-012 计算指数 (5 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, ans = 1;
scanf("%d", &n);
for(int i = 1; i <= n; i++)
ans = ans * 2;
printf("%d^%d = %d\n", 2, n, ans);
return 0;
}
L1-013 计算阶乘和 (10 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int a[15];
void init()
{
a[1] = 1;
for(int i = 2; i <= 10; i++)
a[i] = a[i - 1] * i;
}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, ans = 0;
scanf("%d", &n);
init();
for(int i = 1; i <= n; i++)
ans = ans + a[i];
printf("%d\n", ans);
return 0;
}
L1-014 简单题 (5 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
printf("This is a simple problem.\n");
return 0;
}
L1-015 跟奥巴马一起画方块 (15 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, len;
char s[10];
scanf("%d%s", &n, s);
if(n % 2 == 0)
len = n / 2;
else
len = n / 2 + 1;
for(int i = 1; i <= len; i++)
{
for(int j = 1; j <= n; j++)
printf("%c", s[0]);
printf("\n");
}
return 0;
}
L1-016 查验身份证 (15 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int a[20] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
int b[20] = {1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2};
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, flag = 0;
char s[20];
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
scanf("%s", s);
int num = 0, isok = 0;
for(int i = 0; i < 17; i++)
{
if(s[i] == 'X')
{
isok = 1;
break;
}
//printf("%d %d ", s[i] - '0', a[i]);
num = num + a[i] * (s[i] - '0');
//printf("num: %d\n", num);
}
//printf("\n%d %d\n", num, num % 11);
if(isok)
{
printf("%s\n", s);
continue;
}
num = num % 11;
char x;
if(num != 2)
x = b[num] + '0';
else
x = 'X';
if(x != s[17])
{
flag = 1;
printf("%s\n", s);
}
}
if(flag == 0)
printf("All passed\n");
return 0;
}
L1-017 到底有多二 (15 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
char s[55];
scanf("%s", s);
double ans = 100;
int len = strlen(s), num = 0;
if((s[len - 1] - '0') % 2 == 0)
ans *= 2;
for(int i = 0; i < len; i++)
{
if(s[i] == '2')
num++;
}
ans *= num;
if(s[0] == '-')
{
ans *= 1.5;
len--;
}
ans /= len;
printf("%.2f%\n", ans);
return 0;
}
L1-018 大笨钟 (10 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int h, m;
scanf("%d:%d", &h, &m);
if(h < 12)
printf("Only %02d:%02d. Too early to Dang.\n", h, m);
else if(h == 12)
{
if(m == 0)
printf("Only %02d:%02d. Too early to Dang.\n", h, m);
else
printf("Dang\n");
}
else
{
h -= 12;
if(m > 0)
h++;
for(int i = 0; i < h; i++)
printf("Dang");
printf("\n");
}
return 0;
}
L1-019 谁先倒 (15 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, A, B, a = 0, b = 0, stop = 0, ans;
scanf("%d%d%d", &A, &B, &n);
for(int i = 0; i < n; i++)
{
int ax, ay, bx, by;
scanf("%d%d%d%d", &ax, &ay, &bx, &by);
if(stop)
continue;
if(ax + bx == ay && ax + bx != by)
{
a++;
if(a > A)
{
stop = 1;
ans = 1;
}
}
else if(ax + bx != ay && ax + bx == by)
{
b++;
if(b > B)
{
stop = 1;
ans = 2;
}
}
}
if(ans == 1)
printf("A\n%d\n", b);
else
printf("B\n%d\n", a);
return 0;
}
L1-020 帅到没朋友 (20 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int a[100010];
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, k, x, flag = 1;
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
scanf("%d", &k);
for(int i = 0; i < k; i++)
{
scanf("%d", &x);
if(k == 1)
break;
a[x] = 1;
}
}
scanf("%d", &k);
while(k--)
{
scanf("%d", &x);
if(a[x] == 0)
{
if(flag == 1)
{
flag = 0;
printf("%05d", x);
}
else
printf(" %05d", x);
a[x] = 1; //查询多次只输出一次
}
}
if(flag)
printf("No one is handsome");
//printf("\n");
return 0;
}
L1-021 重要的话说三遍 (5 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
printf("I'm gonna WIN!\n");
printf("I'm gonna WIN!\n");
printf("I'm gonna WIN!\n");
return 0;
}
L1-022 奇偶分家 (10 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, x, ans = 0;
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
scanf("%d", &x);
if(x % 2)
ans++;
}
printf("%d %d\n", ans, n - ans);
return 0;
}
L1-023 输出GPLT (20 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
char s[maxn];
map<char, int> M;
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
M['G'] = 0;
M['P'] = 0;
M['L'] = 0;
M['T'] = 0;
scanf("%s", s);
int len = strlen(s);
for(int i = 0; i < len; i++)
{
if(s[i] == 'G' || s[i] == 'g')
M['G']++;
else if(s[i] == 'P' || s[i] == 'p')
M['P']++;
else if(s[i] == 'L' || s[i] == 'l')
M['L']++;
else if(s[i] == 'T' || s[i] == 't')
M['T']++;
}
while(1)
{
int minx = maxn;
map<char, int>::iterator it;
for(it = M.begin(); it != M.end(); it++)
{
if(it->second > 0 && it->second < minx)
minx = it->second;
}
for(int i = 0; i < minx; i++)
{
if(M['G'] > 0)
printf("G");
if(M['P'] > 0)
printf("P");
if(M['L'] > 0)
printf("L");
if(M['T'] > 0)
printf("T");
}
it = M.begin();
bool isok = true;
while(it != M.end())
{
it->second -= minx;
if(it->second > 0)
isok = false;
it++;
}
if(isok)
break;
}
return 0;
}
L1-024 后天 (5 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n;
scanf("%d", &n);
printf("%d\n", (n + 2) % 7 == 0 ? 7 : (n + 2) % 7);
return 0;
}
L1-025 正整数A+B (15 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
/*
1.结果是0或者结果大于1000,判为?
2.A可以为空串!
所以用一个字符串来模拟比较合适
*/
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
string s;
getline(cin, s); //读一行
int a = 0, b = 0, len = s.length(), flag1 = 1, flag2 = 1;
for(int i = 0; i < len; i++)
{
if(s[i] == ' ')
{
for(int j = 0; j < i; j++)
{
if(s[j] >= '0' && s[j] <= '9')
a = a * 10 + (s[j] - '0');
else
{
flag1 = 0;
break;
}
}
if(i == 0 || a == 0 || a > 1000)
flag1 = 0;
for(int j = i + 1; j < len; j++)
{
if(s[j] >= '0' && s[j] <= '9')
b = b * 10 + (s[j] - '0');
else
{
flag2 = 0;
break;
}
}
if(b == 0 || b > 1000)
flag2 = 0;
break;
}
}
if(flag1)
printf("%d", a);
else
printf("?");
printf(" + ");
if(flag2)
printf("%d", b);
else
printf("?");
if(flag1 && flag2)
printf(" = %d\n", a + b);
else
printf(" = ?\n");
return 0;
}
L1-026 I Love GPLT (5 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
printf("I\n \nL\no\nv\ne\n \nG\nP\nL\nT\n");
return 0;
}
L1-027 出租 (20 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
//set
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int arr[20], index[20];
char s[20];
set<int> S;
int n = 0, m = 0;
scanf("%s", s);
int len = strlen(s);
for(int i = 0; i < len; i++)
S.insert(s[i] - '0');
for(set<int>::iterator it = S.begin(); it != S.end(); it++)
arr[n++] = *it;
for(int i = 0; i < n / 2; i++)
{
int temp = arr[i];
arr[i] = arr[n - i - 1];
arr[n - i - 1] = temp;
}
for(int i = 0; i < len; i++)
{
for(int j = 0; j < n; j++)
{
if(arr[j] == s[i] - '0')
{
index[m++] = j;
break;
}
}
}
printf("int[] arr = new int[]{%d", arr[0]);
for(int i = 1; i < n; i++)
printf(",%d", arr[i]);
printf("};\n");
printf("int[] index = new int[]{%d", index[0]);
for(int i = 1; i < m; i++)
printf(",%d", index[i]);
printf("};\n");
return 0;
}
L1-028 判断素数 (10 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
//数论
bool isprime(int n)
{
if(n == 2 || n == 3)
return true;
if(n % 6 != 1 && n % 6 != 5)
return false;
int m = sqrt(n);
for(int i = 5; i <= m; i += 6)
{
if(n % i == 0 || n % (i + 2) == 0)
return false;
}
return true;
}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
int x;
scanf("%d", &x);
bool flag = isprime(x);
if(flag && x != 1)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
L1-029 是不是太胖了 (5 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
double h, m;
scanf("%lf", &h);
m = (h - 100) * 0.9 * 2;
printf("%.1f\n", m);
return 0;
}
L1-030 一帮一 (15 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
struct Node
{
int sex;
char s[10];
int chosed = 0;
}node[55];
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%d%s", &node[i].sex, node[i].s);
for(int i = 0; i < n; i++)
{
if(node[i].chosed == 1)
continue;
for(int j = n - 1; j >= 0; j--)
{
if(node[j].chosed == 0 && node[i].sex != node[j].sex)
{
node[i].chosed = 1;
node[j].chosed = 1;
printf("%s %s\n", node[i].s, node[j].s);
break;
}
}
}
return 0;
}
L1-031 到底是不是太胖了 (10 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n;
double h, w, a;
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
scanf("%lf%lf", &h, &w);
w /= 2;
a = (h - 100) * 0.9;
if(fabs(a - w) < a * 0.1)
printf("You are wan mei!\n");
else
{
if(w > a)
printf("You are tai pang le!\n");
else
printf("You are tai shou le!\n");
}
}
return 0;
}
L1-032 Left-pad (20 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
string s;
int n, len;
char ch;
cin >> n >> ch;
getchar();
getline(cin, s);
len = s.length();
if(n < len)
{
for(int i = len - n; i < len; i++)
cout << s[i];
}
else
{
for(int i = 0; i < n - len; i++)
cout << ch;
cout << s;
}
return 0;
}
L1-033 出生年 (15 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int judge(int n)
{
set<int> s;
if(n < 1000)
s.insert(0);
while(n)
{
s.insert(n % 10);
n = n / 10;
}
return s.size();
}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int y, n;
scanf("%d%d", &y, &n);
for(int i = 0; ; i++)
{
if(judge(y + i) == n)
{
printf("%d %04d\n", i, y + i);
break;
}
}
return 0;
}
L1-034 点赞 (20 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
map<int, int> m;
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, k, x;
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
scanf("%d", &k);
for(int j = 0; j < k; j++)
{
scanf("%d", &x);
if(m[x] > 0)
m[x]++;
else
m[x] = 1;
}
}
map<int, int>::iterator it = m.begin();
int ans = it->first;
int num = it->second;
it++;
for(it; it != m.end(); it++)
{
if(it->second >= num)
{
ans = it->first;
num = it->second;
}
}
printf("%d %d\n", ans, num);
return 0;
}
L1-035 情人节 (15 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int cnt = 0;
char s[10];
while(1)
{
scanf("%s", s);
if(s[0] == '.')
break;
cnt++;
if(cnt == 2)
printf("%s ", s);
if(cnt == 14)
printf("and %s are inviting you to dinner...\n", s);
}
if(cnt < 2)
printf("Momo... No one is for you ...\n");
else if(cnt < 14)
printf("is the only one for you...\n");
return 0;
}
L1-036 A乘以B (5 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int a, b;
cin >> a >> b;
cout << a * b;
return 0;
}
L1-037 A除以B (10 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int a, b;
scanf("%d%d", &a, &b);
printf("%d/", a);
if(b < 0)
printf("(%d)=", b);
else
printf("%d=", b);
if(b == 0)
printf("Error\n");
else
printf("%.2f\n", (double)a * 1.0 / b);
return 0;
}
L1-038 新世界 (5 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
printf("Hello World\n");
printf("Hello New World\n");
return 0;
}
L1-039 古风排版 (20 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
char ans[110][110];
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n;
string s;
cin >> n;
getchar();
getline(cin, s);
int len = s.length();
int cnt = 0, i, j;
//先把字符输入到矩阵中
//i, j记录了最后一个字符所在的行列
for(i = 0; cnt < len; i++)
{
for(j = 0; j < n; j++)
{
ans[i][j] = s[cnt++];
if(cnt >= len)
break;
}
}
// cout << i << ' ' << j << endl;
//将矩阵向右旋转90°输出
for(int k = 0; k < n; k++)
{
//第一列可能有空格
if(k > j)
printf(" ");
else
printf("%c", ans[i - 1][k]);
for(int l = i - 2; l >= 0; l--)
printf("%c", ans[l][k]);
printf("\n");
}
return 0;
}
L1-040 最佳情侣身高差 (10 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
char ch;
double h, ans;
getchar();
scanf("%c%lf", &ch, &h);
if(ch == 'M')
ans = h / 1.09;
else
ans = h * 1.09;
printf("%.2f\n", ans);
}
return 0;
}
L1-041 寻找250 (10 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, i = 0;
while(1)
{
i++;
scanf("%d", &n);
if(n == 250)
{
printf("%d\n", i);
break;
}
}
return 0;
}
L1-042 日期格式化 (5 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int a, b, c;
scanf("%d-%d-%d", &a, &b, &c);
printf("%d-%02d-%02d\n", c, a, b);
return 0;
}
L1-043 阅览室 (20 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 110;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int a[1010];
int n, x, h, m, t, cnt, sum;
char s[5];
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
memset(a, -1, sizeof(a));
cnt = 0;
sum = 0;
while(1)
{
scanf("%d%s", &x, s);
scanf("%d:%d", &h, &m);
if(x == 0)
break;
t = h * 60 + m;
if(a[x] == -1 && s[0] == 'S')
a[x] = t;
else if(a[x] != -1 && s[0] == 'E')
{
cnt++;
sum = sum + t - a[x];
a[x] = -1; //别忘记清空
}
//网上看题解看到的坑点,感觉不太合理
else if(a[x] != -1 && s[0] == 'S')
a[x] = t;
}
double ans = sum * 1.0 / cnt; //答案要四舍五入
printf("%d %d\n", cnt, cnt == 0 ? 0 : int(ans + 0.5));
}
return 0;
}
L1-044 稳赢 (15 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 110;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int k;
scanf("%d", &k);
char s[10];
int cnt = 0;
while(1)
{
scanf("%s", s);
if(cnt != 0 && cnt % k == 0)
{
if(s[0] == 'E')
break;
printf("%s\n", s);
cnt = 0;
}
else
{
if(s[0] == 'J')
printf("ChuiZi\n");
else if(s[0] == 'C')
printf("Bu\n");
else if(s[0] == 'B')
printf("JianDao\n");
else
break;
cnt++;
}
}
return 0;
}
L1-045 宇宙无敌大招呼 (5 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
string s;
cin >> s;
cout << "Hello " << s;
return 0;
}
L1-047 装睡 (10 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, a, b;
char s[10];
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
scanf("%s%d%d", s, &a, &b);
if(a < 15 || a > 20 || b < 50 || b > 70)
printf("%s\n", s);
}
return 0;
}
L1-048 矩阵A乘以B (15 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 110;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int a[maxn][maxn];
int b[maxn][maxn];
int c[maxn][maxn];
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int ra, ca, rb, cb;
scanf("%d%d", &ra, &ca);
for(int i = 0; i < ra; i++)
for(int j = 0; j < ca; j++)
scanf("%d", &a[i][j]);
scanf("%d%d", &rb, &cb);
for(int i = 0; i < rb; i++)
for(int j = 0; j < cb; j++)
scanf("%d", &b[i][j]);
if(ca != rb)
{
printf("Error: %d != %d\n", ca, rb);
return 0;
}
for(int i = 0; i < ra; i++)
{
for(int j = 0; j < cb; j++)
{
for(int k = 0; k < ca; k++)
c[i][j] = c[i][j] + a[i][k] * b[k][j];
}
}
printf("%d %d\n", ra, cb);
for(int i = 0; i < ra; i++)
{
printf("%d", c[i][0]);
for(int j = 1; j < cb; j++)
printf(" %d", c[i][j]);
printf("\n");
}
return 0;
}
L1-051 打折 (5 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int a, b;
scanf("%d%d", &a, &b);
printf("%.2f\n", (double)a * 1.0 * b / 10);
return 0;
}
L1-052 2018我们要赢 (5 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
printf("2018\nwo3 men2 yao4 ying2 !\n");
return 0;
}
L1-053 电子汪 (10 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int a, b;
cin >> a >> b;
for(int i = 0; i < a + b; i++)
cout << "Wang!";
return 0;
}
L1-054 福到了 (15 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 110;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
char s[maxn][maxn];
char ch[5];
int n, flag = 1;
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
scanf("%s%d", ch, &n);
getchar();//注意getline的回车问题
for(int i = 1; i <= n; i++)
cin.getline(s[i] + 1, n + 1);
// for(int i = 1; i <= n; i++)
// {
// for(int j = 1; j <= n; j++)
// printf("%c", s[i][j]);
// printf("\n");
// }
//判断正过来倒过去是否一样
for(int i = 1; i <= n; i++)
{
if(flag == 0)
break;
for(int j = 1; j <= i; j++)
{
if(s[i][j] != s[n + 1 - i][n + 1 - j])
{
flag = 0;
break;
}
}
}
//输出倒过去的字
if(flag)
printf("bu yong dao le\n");
for(int i = n; i > 0; i--)
{
for(int j = n; j > 0; j--)
{
if(s[i][j] != ' ')
printf("%c", ch[0]);
else
printf(" ");
}
printf("\n");
}
return 0;
}
L1-055 谁是赢家 (10 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int pa, pb, x, qa = 0, qb = 0;
scanf("%d%d", &pa, &pb);
for(int i = 0; i < 3; i++)
{
scanf("%d", &x);
if(x == 0)
qa++;
else
qb++;
}
if(pa > pb && qa > 0|| qa == 3)
printf("The winner is a: %d + %d\n", pa, qa);
else if(pb > pa && qb > 0 || qb == 3)
printf("The winner is b: %d + %d\n", pb, qb);
return 0;
}
L1-056 猜数字 (20 分)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI = atan(1.0)*4;
const int INF = 0x7ffffff;
const ll MOD = 1000000007;
const int maxn = 10010;
ll GCD(ll a, ll b){return b==0?a:GCD(b,a%b);}
char s[maxn][10]; //名字
double a[maxn]; //猜的数字
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n;
double sum = 0;
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
scanf("%s%lf", s[i], &a[i]);
sum += a[i];
}
sum = sum / n / 2;
int cnt = 0;
double ans = fabs(a[0] - sum);
for(int i = 1; i < n; i++)
{
if(fabs(a[i] - sum) < ans)
{
cnt = i;
ans = fabs(a[i] - sum);
}
}
printf("%d %s\n", (int)sum, s[cnt]);
return 0;
}