栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

1033 旧键盘打字 C++

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

1033 旧键盘打字 C++

1033 旧键盘打字

str1是坏掉的键盘,str2是本要输出的字符串
考虑到str2会很长的情况下,就只循环一次str2,先是用的for循环,发现str2的长度在erase的过程中会变短,就用while(!str2.empty())循环,str2[count]代表当前字符,若当前字符有被去掉,去掉后count不变,继续判断下一个字符,若没有去,则count++继续下一个判断。

#include
#include 
// 补充  npos 是一个常数,用来表示不存在的位置 
using namespace std;
string remove(string str1,string str2)
{
	//先判断是否有"+"
	bool flag=false;
	int count=0;
	if((str1.find('+',0) != string::npos))
	{
		flag=true;
	}			
		bool iden=false;
		while(!str2.empty()) 
		{
			if(count==str2.size())  break;
			if(flag==true)
			{
				if((str2[count]>='A'&&str2[count]<='Z'))
				{
					str2.erase(count,1);
					iden=true;
				}
	            else{
	            	for(int j=0;j 

这个代码虽然AC了,但是最后一个测试点用了100多ms,过于长了
我在牛客网这道题的下面找到了一个大佬的代码
这道题的下面第一个
侵删
附上代码:

#include 
#include 
int main(){
 char A[123] = {0}, ch;
 while ((ch = getchar()) != 'n')
  A[ch]++;
 while ((ch = getchar()) != 'n')
  if ((isupper(ch) && A[43]) || A[toupper(ch)]) 
  continue;
  else
  putchar(ch);
 return 0;
}

最后一个测试点也保持在10ms以内
今天又学到了

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/311617.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号