上一页 1 2 3 4 5 6 ··· 11 下一页

2021年10月5日

L1-016 查验身份证 (15 point(s))

摘要: 之前在PAT乙级也写过,这次写完后看了看,发现自己好像少考虑了一个条件 “检查前17位是否全为数字” 。当时只看到前面的条件 “并不检验前17位是否合理” ,所以就没管写出了下面这个代码。但提交后发现也是可以AC的。 稍微想了想,这应该是钻了个漏洞的,如果前十七位存在非数字,那么加权求和的时候就可能 阅读全文

posted @ 2021-10-05 06:50 Atl212 阅读(88) 评论(0) 推荐(0)

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)

2021年10月2日

L1-009 N个数求和 (20 point(s))

摘要: 最大公因数。求公因数用辗转相除法,但是当时忘记部分怎么写了,所以稍微推了推写出了下面这个东西。 ll gcd(ll a, ll b){ return a % b ? gcd(b, a % b) : b; } 但写完之后发现跟辗转相除法的形式不太一样,真正的应该是这样的表示。 ll gcd(ll a, 阅读全文

posted @ 2021-10-02 17:14 Atl212 阅读(94) 评论(0) 推荐(0)

L1-008 求整数段和 (10 point(s))

摘要: 设置宽度,除了 setw() 外还看到一个方法。 cout.width(); 参考代码 Cout.width()的使用 cout的格式控制 #include <bits/stdc++.h> using namespace std; int main(){ int A, B, sum = 0,num 阅读全文

posted @ 2021-10-02 16:29 Atl212 阅读(30) 评论(0) 推荐(0)

2021年9月29日

L1-007 念数字 (10 point(s))

摘要: 求基除余法可能会多写一个函数,所以直接读取字符的方法比较好。 如果是读取字符串的话,需要消去开头的负号再遍历,不然会有问题。 如果不用字符串的方式也可以用读取字符的方法。这样不需要对字符串遍历,更简便。 参考代码 #include <bits/stdc++.h> using namespace st 阅读全文

posted @ 2021-09-29 13:50 Atl212 阅读(82) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 ··· 11 下一页

导航