问题 M: 零基础学C/C++158——删除中间的*


思路很简单,但实现起来有点麻烦。将前面2题融合(前两题我就觉得没必要放了哈哈哈哈),保留前面与后面的*都改成删除即可。
你会发现我的代码是前两个的融合。要学会融会贯通鸭:.゚ヽ(。◕‿◕。)ノ゚.:。+゚

点击查看代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int main ()
{
	char a[81];
	while(gets(a)!=NULL)
	{
		int n=strlen(a);
		for(int i=0;i<n;i++)
		{
			if(a[i]!='*') break;
			else printf("%c",a[i]); 
		}//前端 
		for(int i=0;i<n;i++)
		{
			if(a[i]=='*')
			{
				int flag=0;
				for(int j=i;j<n-1;j++)
				{
					if(a[j]!='*') flag=1;
				}
				if(flag)
				{
					flag=0;
					continue;
				}
			}
			 printf("%c",a[i]);
		}
		printf("\n");//后端 
	}
	return 0;
}


posted @ 2022-11-08 17:04  美羊羊给沸羊羊搬砖  阅读(80)  评论(0)    收藏  举报