AtCoder Beginner Contest 286——B - Cat

AtCoder Beginner Contest 286 题目讲解

A题 B题 C题 D题 E题


蒟蒻来讲题,还望大家喜。若哪有问题,大家尽可提!

Hello, 大家好哇!本初中生蒟蒻今天讲解一下AtCoder Beginner Contest 286的B题——Cat

===========================================================================================

原题

Problem Statement

You are given a string S S S of length N N N.

Find the string obtained by replacing all contiguous occurrences of n a na na in S with n y a nya nya.

Constraints

  • N N N is an integer between 1 1 1 and 1000 1000 1000, inclusive.
  • S S S is a string of length N N N consisting of lowercase English letters.

Input

The input is given from Standard Input in the following format:

N
S

Output

Print the answer.

Sample Input 1

4
naan

Sample Output 1

nyaan

Replacing all contiguous occurrences of n a na na in naan with n y a nya nya results in the string n y a a n nyaan nyaan.

Sample Input 2

4
near

Sample Output 2

near

S may not contain a contiguous na.

Sample Input 3

8
national

Sample Output 3

nyationyal

思路

循环并判断是否是 n a na na,若是输出 n y a nya nya,否则输出 s i s_{i} si


代码

#include <iostream>

using namespace std;

int n;
string s;

int main()
{
	cin >> n >> s;
	
	s = ' ' + s;
	
	for (int i = 1; i <= n; i ++)	
		if (s[i] == 'n' && s[i + 1] == 'a') //如果是
			cout << "nya", i ++; //因为下一个a不用判断了,直接i++
		else//不是
			cout << s[i];

	return 0;
}

今天就到这里了!

大家有什么问题尽管提,我都会尽力回答的!最后,除夕夜祝大家新年快乐!
在这里插入图片描述

吾欲您伸手,点的小赞赞。吾欲您喜欢,点得小关注!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值