博客
关于我
PAT——1040. 有几个PAT
阅读量:463 次
发布时间:2019-03-06

本文共 1275 字,大约阅读时间需要 4 分钟。

字符串APPAPT中包含了两个单词“PAT”,其中第一个PAT是第2位(P),第4位(A),第6位(T);第二个PAT是第3位(P),第4位(A),第6位(T)。

现给定字符串,问一共可以形成多少个PAT?

输入格式:

输入只有一行,包含一个字符串,长度不超过105,只包含P、A、T三种字母。

输出格式:

在一行中输出给定字符串中包含多少个PAT。由于结果可能比较大,只输出对1000000007取余数的结果。

输入样例:

APPAPT

输出样例:

2
1 package com.hone.basical; 2  3 import java.util.Scanner; 4  5 /** 6  * 原题目:https://www.patest.cn/contests/pat-b-practise/1039 7  *  8  * @author Xia 理解题目 9  * 有两个结点运行超时10  * 思路来源:https://www.cnblogs.com/asinlzm/p/4440603.html11  */12 13 public class basicalLevel1040howManyPat {14     public static void main(String[] args) {15         Scanner in = new Scanner(System.in);16         char[] pat = in.nextLine().toCharArray();17         int len = pat.length;18         in.close();19         int numPat = 0, numAt = 0, num = 0;20         // 从后面往前面遍历21         while ((len--) > 0) {22             if (pat[len] == 'T') {23                 numAt++;24             } else if (pat[len] == 'A') {25                 numPat += numAt;26             } else {27                 num += numPat;28                 // 因为输出的结果具有周期性,所以可以提前处理,当参数大于指定的次数的时候29                 // 可以先取余数30                 if (num > 1000000007) {31                     num = num % 1000000007;32                 }33             }34         }35         System.out.println(num);36     }37 }

 

你可能感兴趣的文章
nginx+php的搭建
查看>>
nginx+tomcat+memcached
查看>>
Nginx+Tomcat实现动静分离
查看>>
nginx+Tomcat性能监控
查看>>
nginx+uwsgi+django
查看>>
nginx+vsftp搭建图片服务器
查看>>
Nginx-http-flv-module流媒体服务器搭建+模拟推流+flv.js在前端html和Vue中播放HTTP-FLV视频流
查看>>
nginx-vts + prometheus 监控nginx
查看>>
Nginx/Apache反向代理
查看>>
Nginx: 413 – Request Entity Too Large Error and Solution
查看>>
nginx: [emerg] getpwnam(“www”) failed 错误处理方法
查看>>
nginx: [emerg] the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:
查看>>
nginx:Error ./configure: error: the HTTP rewrite module requires the PCRE library
查看>>
Nginx:objs/Makefile:432: recipe for target ‘objs/src/core/ngx_murmurhash.o‘解决方法
查看>>
Nginx、HAProxy、LVS
查看>>
Nginx下配置codeigniter框架方法
查看>>
Nginx中使用expires指令实现配置浏览器缓存
查看>>
nginx中配置root和alias的区别
查看>>
nginx主要流程(未完成)
查看>>
Nginx之二:nginx.conf简单配置(参数详解)
查看>>