2021年10月4日

L1-015 跟奥巴马一起画方块 (15 point(s))

摘要: 很神奇的字符串的初始化。 string s(n, c); 参考代码 #include <bits/stdc++.h> using namespace std; int main(){ int n; char c; cin >> n >> c; string s(n, c); for(int i = 阅读全文

posted @ 2021-10-04 22:00 Atl212 阅读(80) 评论(0) 推荐(0)

L1-014 简单题 (5 point(s))

摘要: #include <bits/stdc++.h> using namespace std; int main(){ cout << "This is a simple problem."; } 阅读全文

posted @ 2021-10-04 21:56 Atl212 阅读(16) 评论(0) 推荐(0)

L1-013 计算阶乘和 (10 point(s))

摘要: 参考别人的写法发现自己写繁琐了,因为 N! 是连续递增的,所以可以用 s *= n 每次循环乘一次得到新阶乘即可,不需要每次重新循环计算阶乘。 参考代码 #include <bits/stdc++.h> using namespace std; int main(){ int N, ans = 0, 阅读全文

posted @ 2021-10-04 21:55 Atl212 阅读(41) 评论(0) 推荐(0)

L1-012 计算指数 (5 point(s))

摘要: int ans = pow(2, n); 最开始想想直接输出 pow() 函数的返回值,但发现结果都是错的,很不解,所以多声明一变量来保存答案再输出。 看了下关于 pow() 介绍,发现该函数的函数类型是 double 跟这里 %d 的结果可能是不匹配的,所以结果需要进行类型转换 (int) 。 p 阅读全文

posted @ 2021-10-04 21:47 Atl212 阅读(56) 评论(0) 推荐(0)

L1-011 A-B (20 point(s))

摘要: 字符串的末尾是 string::npos 而不是类似其他容器用函数 end() 。 #include <bits/stdc++.h> using namespace std; int main(){ string A, B; getline(cin, A); getline(cin, B); for 阅读全文

posted @ 2021-10-04 21:34 Atl212 阅读(32) 评论(0) 推荐(0)

L1-010 比较大小 (10 point(s))

摘要: #include <bits/stdc++.h> using namespace std; int main(){ int a[3]; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); cout << a[0] << "->" << a[1] << "->" 阅读全文

posted @ 2021-10-04 21:31 Atl212 阅读(43) 评论(0) 推荐(0)

导航