NC216132. Easyproblem
描述
输入描述
Enter a positive integer n in the first line
In the second line, enter a string containing only the characters' x 'and' y '
The range of n is 1 < = n < = 100
输出描述
Output a number k ,which means the minimum number of modifications in a single line.
示例1
输入:
2 xy
输出:
0
C++(clang++11) 解法, 执行用时: 11ms, 内存消耗: 524K, 提交时间: 2021-01-22 16:14:18
#include<bits/stdc++.h> using namespace std; string s; int n; int main() { cin>>n>>s; cout<<abs(count(s.begin(),s.end(),'x')-count(s.begin(),s.end(),'y'))/2; }
pypy3 解法, 执行用时: 67ms, 内存消耗: 21196K, 提交时间: 2023-04-29 14:04:11
import math a=int(input()) r=input() ans=0 for i in r: if i=='x': ans+=1 print(int(math.fabs(ans-(a-ans)))//2)
Python3(3.9) 解法, 执行用时: 19ms, 内存消耗: 2808K, 提交时间: 2021-03-09 13:43:00
n=int(input())//2 a=input() print(abs(a.count('x')-n))