//k题 #includeusing namespace std; int solve(int x, int y) { if (x == 1 && y == 1) return 1; if (x < 1 || y < 1) return 0; else return solve(x, y - 1) + solve(x - 1, y - 1); } int main() { int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 1;i <= n;i++) { int first = 1; for (int j = 1;j <= i;j++) { if (first) first = 0; else cout << " "; cout << solve(j, i); } cout << endl; } } return 0; }
//A题 #include#define endl '\n' using namespace std; #define int long long #define all(a) a.begin(),a.end() using pii = pair ; const int N = 5e5 + 10, M = N, inf = 1e9, mod = 1e9 + 7; void solve() { int n; cin >> n; for (int i = 1;i <= n;i++) {//行数 for (int j = 1;j <= n - i;j++) {//空格 cout << " "; } for (int j = 1;j <= 2 * i - 1;j++) {//数字 cout << n; } cout << endl; } } signed main() { cin.tie(0)->ios::sync_with_stdio(false); int tt; cin >> tt; while (tt--) { solve(); } return 0; }
//C题目 #include#define endl '\n' using namespace std; using pii = pair ; const int N = 5e5 + 10, M = N, inf = 1e9, mod = 1e9 + 7; set arr; void ws(int l, int r) { bool first = true; for (long long i = l;i <= r;i++) { long long sum = 0; //找出因子放入set for (long long j = 1;j <= i;j++) { if (i % j == 0 && i != j) arr.insert(j); } //把所有因子相加 for (auto it = arr.begin();it != arr.end();it++) { sum += *it; } //判断:如果因子和等于此数; if (sum == i) { first = false; cout << i << ";"; } arr.clear(); } if (first) { cout << "0;" << endl; } else cout << endl; } int main() { int a, n, m; cin >> a; while (a--) { cin >> n >> m; ws(n, m); } return 0; }
//D题 #include#define endl '\n' using namespace std; #define int long long #define all(a) a.begin(),a.end() using pii = pair ; const int N = 5e5 + 10, M = N, inf = 1e9, mod = 1e9 + 7; void solve() { int m, n; vector num; while (cin >> m >> n) { while (m) { int u = m % 10; num.push_back(u); m = m / 10; } reverse(num.begin(), num.end()); for (int i = 0;i < n;i++) { cout << num[i]; } cout << endl; num.clear(); } } signed main() { cin.tie(0)->ios::sync_with_stdio(false); int tt=1; while (tt--) { solve(); } return 0; }
//E题目 #include#define endl '\n' using namespace std; #define int long long #define all(a) a.begin(),a.end() using pii = pair ; const int N = 5e7 + 10, M = N, inf = 1e9, mod = 1e9 + 7; vector arr; bool sushu(int n) { int f = sqrt(n) + 1; for (int i = 2; i > n; for (int i = 2;i <=n;i++) { if (sushu(i))arr.push_back(i); } int ans = 0; for (auto it = arr.begin();it != arr.end();it++) { for (auto it2 = it;it2 != arr.end();it2++) { if (*it + *it2 == n) { ans++; *it = 0; *it2 = 0; } } } cout << ans << endl; arr.clear(); } signed main() { cin.tie(0)->ios::sync_with_stdio(false); int tt; cin >> tt; while (tt--) { solve(); } return 0; }
//F题目 #include#define endl '\n' using namespace std; #define int long long #define all(a) a.begin(),a.end() using pii = pair ; const int N = 5e5 + 10, M = N, inf = 1e9, mod = 1e9 + 7; signed main() { cin.tie(0)->ios::sync_with_stdio(false); int tt; cin >> tt; while (tt--) { int n; cin >> n; for (int i = 1;i <= n;i++) { for (int j = 1;j <= n - i;j++) { cout << " "; } for (int j = 1;j <= i;j++) { cout << '*'; } cout << endl; } } return 0; }
//G题目
#include
#define endl '\n'
using namespace std;
#define int long long
#define all(a) a.begin(),a.end()
using pii = pair;
const int N = 5e5 + 10, M = N, inf = 1e9, mod = 1e9 + 7;
signed main() {
cin.tie(0)->ios::sync_with_stdio(false);
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
int sum = 0;
int nine(0);
int eight(0);
int seven(0);
int six(0);
int sb(0);
for (int i = 0;i < n;i++) {
int score;
cin >> score;
if (score >= 90)nine++;
else if (score >= 80)eight++;
else if (score >= 70)seven++;
else if (score >= 60)six++;
else sb++;
sum += score;
}
cout << "Avg:" << sum / n<
//H题目
#include
#define endl '\n'
using namespace std;
#define all(a) a.begin(),a.end()
using pii = pair;
const int N = 5e5 + 10, M = N, inf = 1e9, mod = 1e9 + 7;
int Fibo(int n) {
if (n == 0) return 0;
if (n == 1 || n == 2)return 1;
int one = 1, two = 1, res = 0;
//如果n>3使用迭代
for (int i = 3;i <= n;i++) {
res = one + two;
one = two;
two = res;
}
return res;
}
bool sushu(int x) {
int f = sqrt(x) +1;
for (int i = 2;i > n;
while (n--)
{
cin >> m;
fibPrime(m);
}
return 0;
}
//I题目
#include
#define endl '\n'
using namespace std;
#define int long long
#define all(a) a.begin(),a.end()
using pii = pair;
const int N = 50, M = N, inf = 1e9, mod = 1e9 + 7;
int arr[N][N];
signed main() {
cin.tie(0)->ios::sync_with_stdio(false);
int max = 0;
int min = 100000000;
int x1, y1, x2, y2;
for (int i = 0;i <3;i++) {
for (int j = 0;j <4;j++) {
cin >> arr[i][j];
if (arr[i][j] < min) {
min=arr[i][j];
x1 = i;
y1 = j;
}
if (arr[i][j] > max) {
max=arr[i][j];
x2 = i;
y2 = j;
}
}
}
cout << "max=" << max << "," << x2 << "," << y2 << endl;
cout << "min=" << min << "," << x1 << "," << y1 << endl;
return 0;
}
//J题
#include
#define endl '\n'
using namespace std;
#define int long long
#define all(a) a.begin(),a.end()
using pii = pair;
const int N = 5e5 + 10, M = N, inf = 1e9, mod = 1e9 + 7;
vectorarr;
signed main() {
cin.tie(0)->ios::sync_with_stdio(false);
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
for (int i = 0;i < n;i++) {
int num;
cin >> num;
arr.push_back(num);
}
int num2;
cin >> num2;
arr.push_back(num2);
sort(arr.begin(), arr.end());
bool first = true;
for (auto it:arr) {
if (first)first = false;
else {
cout << ' ';
}
cout << it;
}
cout << endl;
arr.clear();
}
return 0;
}
//由于量太少,直接暴力!
//L题目
#include
#define endl '\n'
using namespace std;
#define int long long
#define all(a) a.begin(),a.end()
using pii = pair;
const int N = 5e2 + 10, M = N, inf = 1e9, mod = 1e9 + 7;
char ch[N];
signed main() {
gets(ch);
char f;
cin>>f;
int len=strlen(ch);
for(int i=0;i
//M题
#include
#define endl '\n'
using namespace std;
#define int long long
#define all(a) a.begin(),a.end()
using pii = pair;
const int N = 5e5 + 10, M = N, inf = 1e9, mod = 1e9 + 7;
char ch[N];
signed main() {
while (cin>>ch) {
int len = strlen(ch);
for (int i = 0;i < len;i++) {
if (isupper(ch[i])) {
ch[i] = tolower(ch[i]);
}
else ch[i] = toupper(ch[i]);
}
cout << ch << endl;
memset(ch, '\n', sizeof(ch));
}
return 0;
}
//N题
#include
#define endl '\n'
using namespace std;
#define int long long
#define all(a) a.begin(),a.end()
using pii = pair;
const int N = 5e2 + 10, M = N, inf = 1e9, mod = 1e9 + 7;
int arr[N][N];
signed main() {
cin.tie(0)->ios::sync_with_stdio(false);
int m, n;
cin >> m >> n;
for (int i = 0;i < m;i++) {
for (int j = 0;j < n;j++) {
cin >> arr[i][j];
}
}
for (int j = 0;j < n;j++) {
int first = 1;
for (int i = 0;i < m;i++) {
if (first)first = 0;
else cout << ' ';
cout << arr[i][j];
}
cout << endl;
}
}
//O题
#include
#define endl '\n'
using namespace std;
#define int long long
#define all(a) a.begin(),a.end()
using pii = pair;
const int N = 5e5 + 10, M = N, inf = 1e9, mod = 1e9 + 7;
signed main() {
cin.tie(0)->ios::sync_with_stdio(false);
int tt;
cin >> tt;
while (tt--) {
char c;
cin >> c;
int num;
cin >> num;
for (int i = c;i
//B题目
#include
#define endl '\n'
using namespace std;
using pii = pair;
const int N = 5e5 + 10, M = N, inf = 1e9, mod = 1e9 + 7;
long long ask(int x) {
long long ans = 1;
for (int i = 2;i <= x;i++) {
ans *= i;
}
return ans;
}
long long sumFactor(int n, int m) {
long long res = 0;
for (int i = n;i <= m;i++) {
res += ask(i);
}
return res;
}
int main()
{
int n, m, s, a;
cin >> a;
while (a--) {
cin >> n >> m;
s = sumFactor(n, m);
cout << s << endl;
}
return 0;
}
花了两小时21分钟做完,慢了三分钟
//L题的另一种用vector的写法
- #include
- using namespace std;
- vector<char>arr;
- int main()
- {
- char f;
- int ans = 0;
- while ((f = getchar()) != '\n') {
- arr.push_back(f);
- }
- char h;
- cin >> h;
- for (auto it = arr.begin();it != arr.end();) {
- if (*it == h) {
- it = arr.erase(it);
- }
- else it++;
- }
- /*
- 或者
- for (auto it = arr.begin();it != arr.end();) {
- arr.erase(remove(arr.begin(),arr.end(),h),arr.end());
- }
- */
- for (auto it = arr.begin();it != arr.end();it++) {
- cout << *it;
- }
- cout << endl;
- }