526 字
3 分钟
L1-036~L1-040的笔记
Samera2022
/
GPLTNotes
Waiting for api.github.com...
00K
0K
0K
Waiting...

P.S. 这份笔记同步发布在我的博客上,建议在博客中查看以享受完整的MD Extended Features. 你可以点此快速跳转到相应页面,我的博客地址为https://samera2022.github.io

L1-036#

代码部分#

L1-036.cpp
#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 A,B;
cin>>A>>B;
cout<<A*B;
return 0;
}

笔记部分#

  • 没有什么好记的。

L1-037#

代码部分#

L1-037.cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//spec A 2/10
int gcd(int a, int b) {
while (b != 0) {
a %= b;
swap(a, b);
}
return a;
}
void solve(int A, int B) {
cout<<A<<"/"<<(B>=0?to_string(B):("("+to_string(B)+")"))<<"=";
if (B==0) {
cout<<"Error";
return;
}
const int multiplier = gcd(abs(A),abs(B));
A /= multiplier;
B /= multiplier;
cout<<fixed<<setprecision(2)<<static_cast<double>(A)/B;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int A, B;
cin>>A>>B;
solve(A,B);
return 0;
}

笔记部分#

  • cout也可以进行格式输出。本段代码所示的为保留两位小数输出,写法为cout<<fixed<<setprecision(2)<<...
  • 除此之外地,它支持填充字符(123->*****123),写法为cout<<setw(int)<<setfill(char)<<...; 进制转换(255->0xff),写法为cout<<showbase<<hex<<...;
  • 特别地,setw(n)仅对下次输出有效,其他操作符都是全局生效。

L1-038#

代码部分#

L1-038.cpp
#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<<"Hello World\nHello New World";
return 0;
}

笔记部分#

  • 没有什么好记的。

L1-039#

代码部分#

L1-039.cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void complete(const int N, string& s) {
const int len = static_cast<int>(s.length());
const int time = N - len % N;
for (int i = 1; i <= time; i++) s.append(" ");
}
void solve(const int N, string& s) {
const int len = static_cast<int>(s.length());
const int col = ((len%N==0) ? 0 : 1 ) + len / N;
complete(N,s);
for (int i = 1; i <= N; i++)
for (int j = col - 1; j >= 0; j--)
cout<<s[j * N + i - 1]<<((j==0)?"\n":"");
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int N;
string s;
cin>>N;
cin.ignore();
getline(cin,s);
solve(N,s);
return 0;
}

笔记部分#

  • 本题需要找一下规律,发现第一行均为len%N==1,第二行均为len%N==2,以此类推,在补空格使得字符串能被N整除之后,根据先前的规律反推即可。

L1-040#

代码部分#

L1-040.cpp
#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;
for (int i = 1; i <= N; i++) {
char gender;
double height;
cin >> gender >> height;
cout<<fixed<<setprecision(2)<<(gender=='M'?height/1.09:height*1.09)<<"\n";
}
return 0;
}

笔记部分#

  • 没有什么好记的。
L1-036~L1-040的笔记
https://samera2022.github.io/posts/Notes/GPLT/l1-036l1-040/
作者
Samera2022
发布于
2026-01-24
许可协议
CC BY-NC-SA 4.0