VSC++:字符串最后单词长度(getchar回车,换行符结束输入)

缘由https://ask.csdn.net/questions/1095116

void 字符串最后单词长度()
{//缘由https://ask.csdn.net/questions/1095116
	int len=0, i=0;
	char str[5000]{};
	while ((str[i] = getchar()) != '\n')++i;//回车即表示输入完成
	while (--i>=0&&str[i] != ' ')++len;
	printf("%d", len);
}
void 字符串最后单词长度()
{//缘由https://ask.csdn.net/questions/1095116
	int len=0, i=0;
	char str[5000]{};
	while ((str[i] = getchar()) != '\n')//回车即表示输入完成
	{ 
		if (str[i] != ' ')++len;
		else len = 0;
		++i; 
	}
	printf("%d", len);
}
void 字符串最后单词长度()
{//缘由https://ask.csdn.net/questions/1095116
	int len=0, i=0;
	char str[5000]{};
	while (i<5000&&(str[i] = getchar()) != '\n')//回车即表示输入完成
		(str[i++] != ' ') ? ++len : len = 0;
	printf("%d", len);
}
//缘由http://ask.csdn.net/questions/1105126
	char a1=' '; int aa = 0;
	while ((a1 = getchar()) != '\n') aa += a1 - '0';
	cout << aa;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值