#include <stdio.h> #include <string.h>

int strrindex(char s[], char t[]) { int slen = strlen(s); int tlen = strlen(t); int i, j, k; for (i = slen - tlen; i >= 0; i--) { for (j = i, k = 0; t[k] != '\0' && s[j] == t[k]; j++, k++); if (k > 0 && t[k] == '\0') { return i; } } return -1; }

int main() { char s[1000], t[1000]; fgets(s, sizeof(s), stdin); fgets(t, sizeof(t), stdin); s[strlen(s) - 1] = '\0'; // 去掉输入字符串末尾的换行符 t[strlen(t) - 1] = '\0'; int index = strrindex(s, t); printf("%d\n", index); return 0;

c语言程序设计字符串位置的查询【问题描述】编写一个函数strrindexst用于返回字符串t在字符串s中最右边出现的位置该位置从0开始计数如果s中不含有t那么返回-1;在你编写的程序中使用strrindexst函数输入ts输出t在s最右边的位置【输入形式】控制台分行输入字符串st【输出形式】控制台输出一个整数是t在s最右边出现的位置【样例输入】The strdup function new ret

原文地址: https://www.cveoy.top/t/topic/fGvt 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录