ACM字符串问题!!

题目在此: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~

阅读 2.1k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进