A.首位不能是0,因此*9,否者*10;
特判只有0的
// Problem: A. Matching
// Contest: Codeforces - Educational Codeforces Round 147 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1821/problem/A
// Memory Limit: 512 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
int a[N];
void Lan(){
string s;
cin>>s;
int n=s.length();
ll ans=1;
int cnt=0;
if(s[0]=='0'){
cout<<0<<'\n';
return;
}
for(int i=0;i<n;i++){
if(s[i]=='?' && i!=0){
ans*=10;
cnt++;
}else if(s[i]=='?' && i==0){
ans*=9;
cnt++;
}
}
cout<<ans<<'\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while (q--) {
Lan();
}
return 0;
}
B.
找到不同的,再遍历一下如果是升序那还可以延申
// Problem: B. Sort the Subarray
// Contest: Codeforces - Educational Codeforces Round 147 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1821/problem/B
// Memory Limit: 512 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
int a[N],b[N];
void Lan(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>b[i];
}
int l=0;
int r=0;
for(int i=1;i<=n;i++){
if(a[i]!=b[i]){
l=i;
break;
}
}
for(int i=n;i>=1;i--){
if(a[i]!=b[i]){
r=i;
break;
}
}
for(int i=l;i>=1;i--){
if(b[i]>b[i+1]){
break;
}
l=i;
}
for(int i=r;i<=n;i++){
if(b[i-1]>b[i]){
break;
}
r=i;
}
cout<<l<<" "<<r<<'\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while (q--) {
Lan();
}
return 0;
}
C.
补题
// Problem: C. Tear It Apart
// Contest: Codeforces - Educational Codeforces Round 147 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1821/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
void Lan(){
string s;
cin>>s;
int ans=INF;
for(int c='a';c<='z';c++){//枚举每一个字母
int res=0;
int len=0;
int n=s.size();
for(int i=0;i<n;i++){//分段
if(s[i]!=c){
len++;
}else{
res=max(res,len);//找最大的段,一次分1/2要log2次分到1,最后再删一次即可,log2+1
len=0;
}
res=max(res,len);//找最大
}
if(!res){
ans=0;
break;
}
ans=min(ans,(int)log2(res)+1);
}
cout<<ans<<'\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while (q--) {
Lan();
}
return 0;
}