电话面试题

和永恒有關 2012-05-29 03:37:35
C#
给你一个string字符串, abcd as,ccd.dsa
反转这个字符串变为: dsa.ccd,as abcd

要求:不能用【任何】【系统函数】。
...全文
3239 79 打赏 收藏 转发到动态 举报
写回复
用AI写文章
79 条回复
切换为时间正序
请发表友善的回复…
发表回复
和永恒有關 2012-06-08
  • 打赏
  • 举报
回复
大致看了下

12,50,60能看懂并且正确

其中50L和60L类似!
和永恒有關 2012-06-08
  • 打赏
  • 举报
回复
都是大牛啊,回头仔细看。先结贴
tangserver 2012-06-05
  • 打赏
  • 举报
回复
[Quote=引用 76 楼 的回复:]

string strAll = "abcd as,ccd.dsa";
string a = "abcd";
string b = "as";
string c = "ccd";
string d = "dsa";

return d+"."+c+","+b+" "+a;

//看 没用任何函数!!!
[/Quote]

还是你叼
imfor 2012-06-05
  • 打赏
  • 举报
回复
string strAll = "abcd as,ccd.dsa";
string a = "abcd";
string b = "as";
string c = "ccd";
string d = "dsa";

return d+"."+c+","+b+" "+a;

//看 没用任何函数!!!
jhdxhj 2012-06-04
  • 打赏
  • 举报
回复
[Quote=引用 33 楼 的回复:]
一个千方百计省钱到极致的变态公司,一个不靠追求而是靠天上掉馅饼的公司。
[/Quote]
这个严重的同意,曾经去用友面试,也遇见过类似的问题,那面试人说:编程这东西,只要给点时间没人弄不出来,关键是你弄出来的办法是否是最好的办法,否则没必要找你了
wheeler 2012-06-04
  • 打赏
  • 举报
回复
How about this?


string ss = "ab,cd.ee ef";
Regex regex = new Regex("([a-zA-Z]+)([,. ]|$)");
Match match = regex.Match(ss);
StringBuilder result = new StringBuilder();
while (match.Success)
{
result.Insert(0, match.Result("$1"));
result.Insert(0, match.Result("$2"));
match = match.NextMatch();
}
Console.WriteLine(result.ToString());
临江仙 2012-06-04
  • 打赏
  • 举报
回复
C++源代码奉上,上个没有复制完整

#include <iostream.h>
#include <string.h>
void main()
{
char s[90]="zhycheng hello world!";

int v=strlen(s);
int half=v/2;
for(int i=0;i<half;i++)
{


char temp=*(s+i);
*(s+i)=*(s+v-i-1);
*(s+v-i-1)=temp;

}
cout<<s<<endl;

}

临江仙 2012-06-04
  • 打赏
  • 举报
回复
C++源代码奉上

#include <iostream.h>
#include <string.h>
void main()
{
char s[90]="zhycheng hello world!";

int v=strlen(s);
int half=v/2;
for(int i=0;i<half;i++)
{


char temp=*(s+i);
*(s+i)=*(s+v-i-1);
*(s+v-i-1)=temp;

}
huorongbj2 2012-06-03
  • 打赏
  • 举报
回复

string str = "abcd as,ccd.dsa"; //output "dsa.ccd,as abcd"
Regex regexNotLetter = new Regex(@"[^a-z]");
Regex regexLetter = new Regex(@"[a-z]+");
Stack stack = new Stack();
Console.WriteLine("start :" + str);

var letterMatches = regexLetter.Matches(str);
var notLetterMatches = regexNotLetter.Matches(str);

for (int i = 0; i < letterMatches.Count; i++)
{
stack.Push(letterMatches[i]);

if (i < notLetterMatches.Count)
{
stack.Push(notLetterMatches[i]);
}
}

Console.Write("result : ");
while (stack.Count > 0)
Console.Write(stack.Pop());

Console.Read();
  • 打赏
  • 举报
回复
表示无压力
xuyuji 2012-06-01
  • 打赏
  • 举报
回复
字母不反转,非字母反转

public static void main(String[] args) {
System.out.println(reverse("asd,fsdf.gfg gdg".toCharArray()));
System.out.println(reverse("9ujf093u4fj.,,mskldjf".toCharArray()));
System.out.println(reverse("j.,/m".toCharArray()));
}

public static char[] reverse(char[] source) {
int len = source.length, t = 0;
char[] target = new char[len];

for (int i = 0; i < len; i++) {
if (!isWord(source[i])) {
copy(source, target, t, i);
t = i + 1;
target[len - i - 1] = source[i];
}
}
copy(source, target, t, len);

return target;
}

public static boolean isWord(char c) {
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
return true;
else
return false;
}

public static void copy(char[] source, char[] target, int start, int end) {
if (start >= end) {
return;
}
int len = source.length - start - end;
for (int i = start; i < end; i++) {
target[i + len] = source[i];
}
}

结果:
gdg gfg.fsdf,asd
mskldjf,,.fj4u390ujf9
m/,.j
anzhiqiang_touzi 2012-06-01
  • 打赏
  • 举报
回复
[Quote=引用 33 楼 的回复:]
一个千方百计省钱到极致的变态公司,一个不靠追求而是靠天上掉馅饼的公司。
[/Quote]
sp老大说的很对
经历过多个公司的我深有同感啊
smamqm 2012-06-01
  • 打赏
  • 举报
回复
你这个不符合要求[Quote=引用 3 楼 的回复:]

从后往前遍历,组合呗
或者,将每个字符压栈,然后遍历栈,所以依次取出就翻转,比如

C# code

string ss = "abcdefg";
Stack<char> stack = new Stack<char>();
foreach (char c in ss)
{
……
[/Quote]
爱在夕阳下 2012-06-01
  • 打赏
  • 举报
回复
public void TurnStr() {
string oldStr = "abcd as,ccd.dsa";
string cutStr = " ,.";
string tempStr = "";//字符串
string re = "";
Stack<string> stack = new Stack<string>();

for (int i = 0; i <= oldStr.Length - 1; i++)
{
char c = oldStr[i];
bool iscut = false;
foreach (char cut in cutStr)
{
if (cut == c)
{
iscut = true;
continue;
}
}
if (iscut)
{
stack.Push(tempStr);
tempStr = "";
stack.Push(c.ToString());
}
else
{
tempStr += c.ToString();
}
}
if (tempStr != "")
{
stack.Push(tempStr);
tempStr = "";
}
foreach (var item in stack)
{
re += item.ToString();
}
string s = re;
}


E次奥 2012-06-01
  • 打赏
  • 举报
回复
简单啊.string str字符串可以看做数组。

定义多个变量。

循环数组.

把str里的值分别用多个字符串存储。

然后组合即可。
sunylf 2012-06-01
  • 打赏
  • 举报
回复
用空格為分格符,進行反轉.
mjf_2008 2012-06-01
  • 打赏
  • 举报
回复
今天儿童节。

static void Main(string[] args)
{
string str = "Hello, you are the $#@ god*&^of^ the&world!";
Regex reg = new Regex("^[A-Za-z]$");

List<string> result = new List<string>();
string word = string.Empty;
foreach (var c in str.ToArray())
{
if (reg.IsMatch(c.ToString()))
{
word += c;
}
else
{
result.Add(word);
result.Add(c.ToString());
word = string.Empty;
}
}

result.Add(word);

for (int i = result.Count - 1; i >= 0; i--)
{
Console.Write(result[i]);
}

Console.ReadKey();
}

阿非 2012-06-01
  • 打赏
  • 举报
回复

static void Main(string[] args)
{
string str = "abcd as,ccd.dsa";
Console.WriteLine(CustomReverse(str));
Console.Read();
}

static string CustomReverse(string str)
{
string result = "", temp = "";
for (int i = 0; i < str.Length; i++)
{
//if (Char.IsLetter(str[i]))
if (str[i] != ' ' && str[i] != ',' && str[i] != '.')
{
temp += str[i];
}
else
{
result = str[i] + temp + result;
temp = "";
}
}
result = temp + result;
return result;
}
cheniwantyou 2012-06-01
  • 打赏
  • 举报
回复
这样的题目都能把你们给纠结的?有没搞错!
说这种题目没意义的只说明你没做过真正的软件!只是在增删改
chengzq 2012-05-31
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

引用 2 楼 的回复:
加载到数组,从下标向上标读取.


从下向上取,不满足条件,好好看题
[/Quote]
为什么不满足条件啊?
有没有让你一个字符一个字符的加载到数组....
加载更多回复(54)

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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