ACM字符串问题!!

发布于 2022-09-04 20:49:43 字数 918 浏览 20 评论 0

题目在此:http://noi.openjudge.cn/ch010...

我的代码如下:

#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
int main()
{
    //freopen("my.in", "r", stdin);
    char str[305];
    string s, s1, s2;
    int cnt = 0;
    cin >> str;
    s = strtok(str, ",");
    s1 = strtok(NULL, ",");
    s2 = strtok(NULL, ",");
    int index1s = s.find_first_of(s1);
    int index1e = s.find_last_of(s1);
    int index2s = s.find_first_of(s2);
    int index2e = s.find_last_of(s2);
    if (index1s == string::npos || index2s == string::npos || index1e+s1.length()>index2s)
        cout << "-1" << endl;
    else
        cout << index2e - index1s - s1.length() - 1 << endl;
    return 0;
}

但是提交后总是5分,,看了半天感觉没问题啊,希望高手能帮忙看下!谢谢啦!O(∩_∩)O~

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文