Get string length which includes Chinese character

 

Get the length of string that may include Chinese character.

a = system.text.encoding.default.getbytes(str);

a.length;

In the this length calculation,Chinese Character will be 2, English character wiil be 1.

 

你必须对该题目采用记忆化搜索!!!!!!!!!!!!我的代码为什么结果输出不对#include<bits/stdc++.h> using namespace std; unordered_map<string,int> mp; int t,n; string s; int dfs(string s) { if(mp.count(s))return mp[s]; if(s.size()==1)return mp[s]=1; string l=s,r=s; int res=0; int a=s.find("01"),b=s.find("10"); if(a==-1&&b==-1)return mp[s]=0; if(a!=-1) { l.replace(a,2,"1"); res+=dfs(l); } if(b!=-1) { r.replace(b,2,"0"); res+=dfs(r); } return mp[s]=res; } int main( ) { cin>>t; while(t–) { cin>>n>>s; cout<<n+dfs(s)<<‘\n’; } return 0; }MC0320 狠狠地对字符串做你想做的事吧 难度: 黄金 时间限制:1秒 占用内存:128 M 收藏 报错 对一个字符串 S S ,有以下两种操作: • 将子串 01 替换为 1 • 将子串 10 替换为 0 总共 t t组数据,每组的 S S都是一个给定长度为 n n的 01 串。 求每组数据中, S S一共有多少个子串,能经过若干次操作,变成长度为1的字符串。 格式 输入格式: 第一行包含一个整数 t ( 1 ≤ t ≤ 1000 ) t(1≤t≤1000) 表示 t t组数据; 每组的第一行包含一个整数 n n表示 S S的长度; 每组的第二行包含一个由 n n个字符 S 1 , S 2 , … , S n S 1 ​ ,S 2 ​ ,…,S n ​ 组成的二进制字符串 S S( 其中 S i 0 S i ​ =0或 S i 1 S i ​ =1)。 输出格式: 针对每个测试用例,输出该字符串满足题意的子串个数。 样例 1 输入: 5 1 1 2 01 3 100 4 1001 5 11111 复制 输出: 1 3 4 8 5 复制 备注 其中: 1 ≤ t ≤ 1000 , 1 ≤ n ≤ 2 × 1 0 5 , ∑ n ≤ 2 ∗ 1 0 5 1≤t≤1000,1≤n≤2×10 5 ,∑ n ​ ≤2∗10 5 ,保证所有测试用例的 n 总和不超过 2 × 1 0 5 2×10 5 。
最新发布
08-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值