| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1184 人关注过本帖
标题:代码wrong answer UVa 10340
只看楼主 加入收藏
ZZCaleb
Rank: 1
等 级:新手上路
帖 子:5
专家分:3
注 册:2018-4-12
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
代码wrong answer UVa 10340
这个代码总是提交时wrong answer,各位帮忙看看,谢谢啦

UVa 10340  https://

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

const int maxn = 100010;
char s[maxn],t[maxn];
int main()
{
    //freopen("3-9.txt","r",stdin);
    while(scanf("%s%s",s,t) != EOF)
    {
    int sl = strlen(s),tl = strlen(t),k = 1;
    if(sl >= tl)
    {
        if(!strcmp(s,t))
        printf("Yes\n");
        else printf("No\n");
    }
    else
    {
        for(int i = 0; i < sl; i++)
        {
            if(strchr(t,s[i])) continue;
            k = 0;
            break;
        }
        if(k == 0)  printf("No\n");
        else
        {
            int sum = 0, m = 0, n = 0;
            for(int i = n; i < sl; i++)
                for(int j = m; j < tl; j++)
                {
                    if(s[i] == t[j])
                    {
                        sum++;
                        m = j;
                        n = i;
                        break;
                    }
                }
            if(sum == sl)
            printf("Yes\n");
            else   printf("No\n");
        }
    }
    }   
    return 0;
 }
搜索更多相关主题的帖子: 代码 wrong answer int printf 
2018-04-12 09:29
九转星河
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:长长久久
等 级:贵宾
威 望:52
帖 子:5023
专家分:14003
注 册:2016-10-22
收藏
得分:10 
先贴题目,(那个OJ平台要登录,看不了具体)~

https://blog.

题目:子序列

题目描述:

输入两个字符串s和t,判断是否可以从t中删除0个或多个字符(其它字符顺序不变),得到字符串s.

例如:abcde可以得到bce,但无法得到dc.


那我也发个链接~

[此贴子已经被作者于2018-4-12 09:47编辑过]


[code]/*~个性签名:bug是什么意思?bug是看上去没有可能的东西实际上是有可能做到的 就是这样~2018-08-08更~*/[/code]
2018-04-12 09:44
九转星河
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:长长久久
等 级:贵宾
威 望:52
帖 子:5023
专家分:14003
注 册:2016-10-22
收藏
得分:0 
一楼的代码用了两个循环可以说是超时了~

题目的大意就是说找到的第一个可以匹配的字符必然是第一个符合要求的字符~
不能匹配的字符直接删去也不影响结果,也就是说跳过不能匹配的字符,如果找到匹配的字符直接看下一个需要匹配的就可以了,说白了都在那简单的代码里面~

[code]/*~个性签名:bug是什么意思?bug是看上去没有可能的东西实际上是有可能做到的 就是这样~2018-08-08更~*/[/code]
2018-04-12 10:08
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:10 
回复 2楼 九转星河
我csdn上不了(好像证书有问题)

You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way. Because of pending patent issues we will not discuss in detail how the strings are generated and inserted into the original message. To validate your method, however, it is necessary to write a program that checks if the message is really encoded in the final string.
Given two strings s and t, you have to decide whether s is a subsequence of t, i.e. if you can remove characters from t such that the concatenation of the remaining characters is s.

Input
The input contains several testcases. Each is specified by two strings s, t of alphanumeric ASCII characters separated by whitespace. Input is terminated by EOF.

Output
For each test case output, if s is a subsequence of t.

Sample Input
sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

Sample Output
Yes
No
Yes
No

2018-04-12 11:50
九转星河
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:长长久久
等 级:贵宾
威 望:52
帖 子:5023
专家分:14003
注 册:2016-10-22
收藏
得分:0 
回复 4楼 rjsp
证书问题这个我不知道具体情况也不好解决(要是可以解决的你自己本人已经解决了)

那里其实也没什么可以说的,里面一个程序已经可以说明一切了~

程序代码:
//子序列.cpp
//2014.7.7
#include <iostream>
#include <string>
using namespace std;

bool isAll_in_All(string s,string t)
{
    int len1 = 0;
    for(int i = 0; i < t.size(); i++)
    {
        if(s[len1] == t[i])
            len1++;
    }
    if(len1 == s.size())
        return 1;
    else
        return 0;
}

int main()
{
    string s,t;
    while(cin >> s >> t)
    {
        if(isAll_in_All(s,t))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}


[code]/*~个性签名:bug是什么意思?bug是看上去没有可能的东西实际上是有可能做到的 就是这样~2018-08-08更~*/[/code]
2018-04-12 11:57
快速回复:代码wrong answer UVa 10340
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016510 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved