|
发表于 2021-10-26 14:10:16
|
显示全部楼层
本帖最后由 jackz007 于 2021-10-26 14:20 编辑
- #include <stdio.h>
- int main(void)
- {
- char s[256] ;
- int d , k , m ;
- gets(s) ;
- for(m = 0 ; s[m] ; m ++) ;
- if(m > 3) {
- for(d = k = 0 ; k < m - 3 ; k ++) {
- if(s[k] == '2' && s[k + 1] == '0' && s[k + 2] == '2' && s[k + 3] == '0') {
- d ++ ;
- k += 3 ;
- }
- }
- printf("%d\n" , d) ;
- } else {
- printf("字符数太少\n") ;
- }
- }
复制代码
编译、运行实况:
- D:\00.Excise\C>g++ -o x x.c
- D:\00.Excise\C>x
- 2020
- 1
- D:\00.Excise\C>x
- 20202020
- 2
- D:\00.Excise\C>x
- 202012320202012202020
- 3
- D:\00.Excise\C>
复制代码 |
|