0
点赞
收藏
分享

微信扫一扫

abc 236 -chukodai题解报告

止止_8fc8 2022-02-06 阅读 60
p2plinqwpf

Problem Statement

You are given a string S consisting of lowercase English letters. Swap the a-th and b-th characters from the beginning of S and print the resulting string.

Constraints

  • S is a string consisting of lowercase English letters.
  • The length of S, ∣S∣, satisfies 2\leqslant \left | s \right |\leqslant 10.
  • 1≤a<b≤∣S∣
  • a and b are integers.

Standard input and output

Input: a string S and two integers which called a, b;

output: The result string

题目翻译

给你字符串,交换第a个与第b个,很简单的一个问题。注意c++下标从0开始,而样例从1开始。交换用swap\left ( s[a-1],s[b-1] \right ).

下面为题解样例程序:

#include <iostream>
#include <string>
using namespace std;

int main(void)
{
  string s;
  int a, b;
  cin >> s >> a >> b;
  
  char tmp = s[a-1];
  s[a-1] = s[b-1];
  s[b-1] = tmp;
  
  cout << s << endl;
  
  return 0;
}
举报

相关推荐

0 条评论