A、小L的作文
暴力枚举,枚举到字符x就加一分
代码如下:
#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int N = 1e4 + 10; char c; char s[N]; int main(){ cin >> c >> s; int lens = strlen(s); int ans = 0; for(int i = 0; i < lens; i ++ ) if(s[i] == c) ans ++; cout<<ans; return 0; }
B、小L的多项式
题目分析:
代码如下:
#include<cstdio> #include<iostream> using namespace std; typedef long long ll; const int N = 1e3 + 10; const int p = 998244353; int n,m; ll a[N]; int main(){ cin >> n; for(int i = 0; i <= n; i ++ ) cin >> a[i]; cin >> m; for(int i = 1; i <= m; i ++ ){ if(i - 1) cout<<" "; ll x; cin >> x; ll ans = 0; for(int i = n; i >= 0; i --){ ans = (ans * x + a[i])%p; } cout<<ans; } return 0; }
C、小L的编辑器
题目分析:
- 分别找两个字符数组存储左右两边枚举的字符,最后按要求输出。
代码如下:
#include<cstdio> #include<cstring> #include<iostream> #include<string> using namespace std; const int N = 1e6+10; string a,b; int cnt1,cnt2; char ans1[N],ans2[N]; int main(){ cin >> a >> b; int n = a.size(); for(int i = 0; i < n; i ++ ){ if(b[i] == 'L') ans1[cnt1++] = a[i]; else ans2[cnt2++] = a[i]; } for(int i = 0; i < cnt2; i ++ ) cout<<ans2[i]; for(int i = cnt1-1; i >= 0; i -- ) cout<<ans1[i]; return 0; }