474 字
2 分钟
L1-021~L1-025的笔记
Waiting for api.github.com...
P.S. 这份笔记同步发布在我的博客上,建议在博客中查看以享受完整的MD Extended Features. 你可以点此快速跳转到相应页面,我的博客地址为https://samera2022.github.io
L1-021
代码部分
#include <bits/stdc++.h>using namespace std;typedef long long ll;
int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout<<"I'm gonna WIN!\n"; cout<<"I'm gonna WIN!\n"; cout<<"I'm gonna WIN!\n"; return 0;}笔记部分
- 没有什么好记的。
L1-022
代码部分
#include <bits/stdc++.h>using namespace std;typedef long long ll;
int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int N; cin>>N; int oddNum = 0; for (int i = 1; i <= N; i++) { int temp; cin>>temp; if (temp%2==1) oddNum++; } cout<<oddNum<<" "<<N-oddNum; return 0;}笔记部分
- 没有什么好记的。
L1-023
代码部分
#include <bits/stdc++.h>using namespace std;typedef long long ll;
int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int g, p ,l ,t; g=p=l=t=0; string input; cin>>input; const int len = static_cast<int>(input.length()); for (int i = 1; i <= len; i++) { switch (input[i-1]) { case 'g': case 'G': g++; break; case 'p': case 'P': p++; break; case 'l': case 'L': l++; break; case 't': case 'T': t++; break; default: break; } } while (g!=0||p!=0||l!=0||t!=0) { if (g!=0) { cout<<"G"; g--; } if (p!=0) { cout<<"P"; p--; } if (l!=0) { cout<<"L"; l--; } if (t!=0) { cout<<"T"; t--; } } return 0;}笔记部分
- 没有什么好记的。
L1-024
代码部分
#include <bits/stdc++.h>using namespace std;typedef long long ll;
int num[] = {3,4,5,6,7,1,2};
int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int D; cin>>D; cout<<num[D-1]; return 0;}笔记部分
- 没有什么好记的。
L1-025
代码部分
#include <bits/stdc++.h>using namespace std;typedef long long ll;//spec 1/15
int formatString(const string &a);
int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); string a,b,c; cin>>a>>b>>c; const int numA = formatString(a); int numB; if (c.empty()) numB = formatString(b); else numB = -1; cout<<(numA==-1?"?":to_string(numA))<<" + "<<(numB==-1?"?":to_string(numB))<<" = "<<((numA==-1||numB==-1)?"?":to_string(numA+numB)); return 0;}
int formatString(const string &a) { if (const int aLen = static_cast<int>(a.length()); aLen==4&&a=="1000") return 1000; else if (aLen<4&&a!="0") for (int i = 1; i <= aLen; i++) { if (!isdigit(a[i-1])) return -1; } else return -1; return stoi(a);}笔记部分
- 【再次强调】C++中
char转String不能使用to_string(char)。如果已经确定char为数字,则可用char - '0'转为int类型,而后使用to_string(int),即to_string(char-'0')。如果char未被确定类型(数字也可以),则直接使用string(1,char)即可。
L1-021~L1-025的笔记
https://samera2022.github.io/posts/Notes/GPLT/l1-021l1-025/