Codeforces Round #560 (Div. 3)

题目大意:给定一个十进制的01串,使得他对10^x取模后结果等于10^y.

思路直接枚举后x位数字,当前仅当倒数第y+1个位置数字为1,其余位置为0时等式成立,从后往前依次遍历即可。

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<cstdio>
 5 #include<queue>
 6 #include<vector>
 7 #include<cmath>
 8 #include<map>
 9 #include<set>
10 using namespace std;
11 typedef long long LL;
12 const int maxn = 1e5+10;
13 LL n,x,y;
14 string str;
15 int main()
16 {
17     while(cin>>n>>x>>y){
18         int ans = 0,tmp=0;
19         cin>>str;
20         reverse(str.begin(),str.end());
21         for(int i=0;i<x;i++){
22             if(i==y&&str[i]!='1')ans++;
23             else if(i!=y&&str[i]=='1')ans++;
24         }
25         cout<<ans<<endl;
26     }
27     return 0;
28 }
View Code

相关文章:

  • 2021-10-27
  • 2021-10-20
  • 2021-08-22
  • 2021-07-24
  • 2021-10-21
  • 2022-01-08
  • 2021-09-09
  • 2021-11-08
猜你喜欢
  • 2021-11-07
  • 2021-10-21
  • 2022-12-23
  • 2021-09-01
  • 2021-04-06
  • 2021-05-01
  • 2022-01-15
相关资源
相似解决方案