关于英雄会答题

javayiwentiwen 2014-03-05 05:18:03
比如说这个题吧
http://hero.csdn.net/Question/Details?ID=350&ExamID=345


题目详情


如果字符串str3能够由str1和str2中的字符按顺序交替形成,那么称str3为str1和str2的交替字符串。例如str1="abc",str2="def",那么"adbecf", "abcdef", "abdecf", "abcdef", "adefbc"等等都为str1和str2的交替字符串。更形式化的,str3的生成算法如下:

str3=""

while str1不为空 or str2不为空:

把str1或str2的首字符加入到str3,并从str1或str2中删除相应的字符

end

给定str1, str2,和str3,判断str3是否为str1和str2的交替字符串。




输入格式:

多组数据,每组数据三行,分别是str1,str2,str3。str1,str2的长度在[1..100]范围内,str3的范围在[1..200]范围内。字符串只包含小写英文字母。

输出格式:

每组数据输出一行YES或者NO。


答题说明


输入样例

a

b

ab

a

b

ca

输出样例:

YES

NO


它到底是怎么接收输入参数的?

尝试过main函数加上Args,Console.ReadLine,都不行。

我代码写得怎么不好了。贴出来请大家评判下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

public class Test
{
static bool foo(string s1, string s2, string s)
{
char[] d1 = s1.ToCharArray();
char[] d2 = s2.ToCharArray();
char[] d = s.ToCharArray();
int i1 = 0;
int i2 = 0;
if (d1.Length + d2.Length != d.Length) return false;
for (int i = 0; i < d.Length; i++)
{
if (i1 < d1.Length && d[i] == d1[i1])
{
i1++;
}
else
{
if (i2 < d2.Length && d[i] == d2[i2])
{
i2++;
}
else
{
return false;
}
}
}
return (i1 == d1.Length && i2 == d2.Length);
}
public static String getInfo(String str)
{
string[] data = str.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
List<string> result = new List<string>();
for (int i = 0; i < data.Length / 3; i++)
{
string s1 = data[i * 3];
string s2 = data[i * 3 + 1];
string s3 = data[i * 3 + 2];
result.Add(foo(s1, s2, s3) ? "YES" : "NO");
}
return string.Join("\r\n", result);
}
public static void Main(string[] Args)
{
if (Args.Length == 0) Args = new string[] { "" };
Console.WriteLine(getInfo(Args[0]));
}
}


希望有工作人员告诉我到底怎么接收输入数据!!!我觉得被愚弄了,很不爽。
...全文
567 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
爽云 2015-02-16
  • 打赏
  • 举报
回复
以前我搭建过OJ平台, 所以很清楚: 机器处理的逻辑是: 1. 将你的代码编译成可执行文件. , 比如: p0001.exe 2. 然后, 通过系统重定向输入输出的办法. 生成结果文件. 就是, 通过dos命令: p0001.exe < test.in >result.out 3.然后, 通过比对result.out来判断结果是否正确.
爽云 2015-02-16
  • 打赏
  • 举报
回复
输入输出示例:

class Program
{
static void Main(string[] args)
{
var cin = Console.In;
var cout = Console.Out;

while(cin.Peek() > 0)
{
var line = cin.ReadLine();

cout.WriteLine(line);
}
}
}


本地测试步骤:
1. 在解决方案管理器中, 右击<项目名>, -> 选择[属性], 打开项目属性设置.
2. 打开[调试]选项卡 -> [启动选项] -> 命令行参数: <test.in >result.out, -> 保存.
3. 右击项目 -> 新建项 -> 文本文件 -> test.in文件, 用vs2012打开, 将题目中的测试用例输入该文件中,
复制的话, 请注意最后一行的换行符. (输出的时候, 也要注意, 因为是机器在判断结果, 所以, 多一个字符都是错的)
4. 右击test.in -> 属性 -> 复制到输出目录 -> 选择"始终复制".

javayiwentiwen 2014-03-12
  • 打赏
  • 举报
回复
谢谢大家的回答。
youzelin 2014-03-07
  • 打赏
  • 举报
回复
在 ACM 等类似的竞技类程序比赛中,C# 的程序输入使用 Console.ReadLine 或者 Console.ReadKey
mnxm 2014-03-07
  • 打赏
  • 举报
回复
引用 11 楼 u013850837 的回复:
[quote=引用 10 楼 mamihong 的回复:] 不用试了,他们的系统有问题,OJ模式对C#和java都出错,昨天我都试了一天,没一道OJ模式的题能提交上去,后来看到他们发的,系统有问题,无语啊,你也是用C#的啊,以后多交流。
什么叫OJ模式?[/quote] Online Judge
javayiwentiwen 2014-03-07
  • 打赏
  • 举报
回复
引用 10 楼 mamihong 的回复:
不用试了,他们的系统有问题,OJ模式对C#和java都出错,昨天我都试了一天,没一道OJ模式的题能提交上去,后来看到他们发的,系统有问题,无语啊,你也是用C#的啊,以后多交流。
什么叫OJ模式?
QQ:21862245 2014-03-07
  • 打赏
  • 举报
回复
不用试了,他们的系统有问题,OJ模式对C#和java都出错,昨天我都试了一天,没一道OJ模式的题能提交上去,后来看到他们发的,系统有问题,无语啊,你也是用C#的啊,以后多交流。
v_JULY_v 2014-03-06
  • 打赏
  • 举报
回复
换C/C++ 试试。
贾牧青 2014-03-06
  • 打赏
  • 举报
回复
= =悲剧啊
KeepSayingNo 2014-03-06
  • 打赏
  • 举报
回复
我觉得人家在意的是你的算法,不在乎怎么样输入吧
Regan-lin 2014-03-06
  • 打赏
  • 举报
回复
java和c#现在写的都超时的,只有c++写的不超时···
javayiwentiwen 2014-03-05
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

public class Test
{
    static bool foo(string s1, string s2, string s)
    {
        char[] d1 = s1.ToCharArray();
        char[] d2 = s2.ToCharArray();
        char[] d = s.ToCharArray();
        int i1 = 0;
        int i2 = 0;
        if (d1.Length + d2.Length != d.Length) return false;
        for (int i = 0; i < d.Length; i++)
        {
            if (i1 < d1.Length && d[i] == d1[i1])
            {
                i1++;
            }
            else
            {
                if (i2 < d2.Length && d[i] == d2[i2])
                {
                    i2++;
                }
                else
                {
                    return false;
                }
            }
        }
        return (i1 == d1.Length && i2 == d2.Length);
    }
    public static String getInfo(String str)
    {
        string[] data = str.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
        List<string> result = new List<string>();
        for (int i = 0; i < data.Length / 3; i++)
        {
            string s1 = data[i * 3];
            string s2 = data[i * 3 + 1];
            string s3 = data[i * 3 + 2];
            result.Add(foo(s1, s2, s3) ? "YES" : "NO");
        }
        return string.Join("\r\n", result);
    }
    public static void Main()
    {
        string s1 = "", s2 = "", s3 = "";
        string tmp = "";
        do
        {
            s1 = tmp == "" ? Console.ReadLine() : tmp;
            s2 = Console.ReadLine();
            s3 = Console.ReadLine();
            Console.WriteLine(getInfo(s1 + "\r\n" + s2 + "\r\n" + s3));
            tmp = Console.ReadLine();
        } while (false);
    }
}
这样写,也就是只接受一组数据,都超时。
javayiwentiwen 2014-03-05
  • 打赏
  • 举报
回复
引用 2 楼 v_JULY_v 的回复:
给你贴一个 主函数例子:
int main() {
string a,b,c;
    while (scanf("%s%s%s",s1,s2,s3) != EOF) {
        a = s1;
        b = s2;
        c = s3;
        puts(isInterleaving(a,b,c)?"YES":"NO");
    }
    return 0;
}
C#有点不同。 Console.ReadLine会导致程序挂起,我无法判断输入结束。 所以总是超时。
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

public class Test
{
    static bool foo(string s1, string s2, string s)
    {
        char[] d1 = s1.ToCharArray();
        char[] d2 = s2.ToCharArray();
        char[] d = s.ToCharArray();
        int i1 = 0;
        int i2 = 0;
        if (d1.Length + d2.Length != d.Length) return false;
        for (int i = 0; i < d.Length; i++)
        {
            if (i1 < d1.Length && d[i] == d1[i1])
            {
                i1++;
            }
            else
            {
                if (i2 < d2.Length && d[i] == d2[i2])
                {
                    i2++;
                }
                else
                {
                    return false;
                }
            }
        }
        return (i1 == d1.Length && i2 == d2.Length);
    }
    public static String getInfo(String str)
    {
        string[] data = str.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
        List<string> result = new List<string>();
        for (int i = 0; i < data.Length / 3; i++)
        {
            string s1 = data[i * 3];
            string s2 = data[i * 3 + 1];
            string s3 = data[i * 3 + 2];
            result.Add(foo(s1, s2, s3) ? "YES" : "NO");
        }
        return string.Join("\r\n", result);
    }
    public static void Main()
    {
        string s1 = "", s2 = "", s3 = "";
        string tmp = "";
        do
        {
            s1 = tmp == "" ? Console.ReadLine() : tmp;
            s2 = Console.ReadLine();
            s3 = Console.ReadLine();
            Console.WriteLine(getInfo(s1 + "\r\n" + s2 + "\r\n" + s3));
            tmp = Console.ReadLine();
        } while (tmp != "");
    }
}
javayiwentiwen 2014-03-05
  • 打赏
  • 举报
回复
引用 2 楼 v_JULY_v 的回复:
给你贴一个 主函数例子:
int main() {
string a,b,c;
    while (scanf("%s%s%s",s1,s2,s3) != EOF) {
        a = s1;
        b = s2;
        c = s3;
        puts(isInterleaving(a,b,c)?"YES":"NO");
    }
    return 0;
}
谢谢july,我看下。
v_JULY_v 2014-03-05
  • 打赏
  • 举报
回复
给你贴一个 主函数例子:
int main() {
string a,b,c;
    while (scanf("%s%s%s",s1,s2,s3) != EOF) {
        a = s1;
        b = s2;
        c = s3;
        puts(isInterleaving(a,b,c)?"YES":"NO");
    }
    return 0;
}
我本良人 2014-03-05
  • 打赏
  • 举报
回复
还是默默的在角落画圈圈吧我

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧