四级试卷2024原卷第1套

四级试卷2024原卷第1套

首页技巧更新时间:2025-03-02 01:00:38
  1. 单项选择

2 判断题

3 编程题

相似字符串

参考程序

#include <bits/stdc .h> using namespace std; bool check(string& A, string& B){ int lena = A.size(), lenb = B.size(); if(lena == lenb){ if(A == B) return true; int cnt = 0; for(int i = 0; i < lena; i ) if(A[i] != B[i]) cnt ; if(cnt == 1) return true; else return false; } if(lena < lenb) return check(B, A); int cnt = 0; for(int i = 0, j = 0; i < lena; i ){ if(A[i] == B[j]) j ; else cnt ; } if(cnt == 1) return true; else return false; } int main() { int T; cin >> T; while(T--){ string A, B; cin >> A >> B; if(check(A, B)) puts("similar"); else puts("not similar"); } return 0; }

做题

参考程序

#include <bits/stdc .h> using namespace std; const int N = 1e6 10; int n; int a[N]; int main() { cin >> n; for(int i = 1; i <= n; i ) cin >> a[i]; sort(a 1, a n 1); // for(int i = 1; i <= n; i ) cout << a[i] << ' '; // puts(""); int cnt = 1; for(int i = 1; i <= n; i ){ // cout << a[i] << ' ' << cnt << endl; if(a[i] < cnt) continue; else cnt ; } cout << --cnt; return 0; }

,
大家还看了
也许喜欢
更多栏目

© 1998-2024 shitiku.com.cn,All Rights Reserved.