本人惭愧求教:对字符串的简单操作

cf1944 2005-07-20 03:50:39
本人今天开始学C#,对C/C++也无基础,碰到一道简单的基础题目做不出来,故请教各位大虾.谢谢了...
假设有一个段程序对字符进行加密,加密后的字符串的第一个字符是原字符串的最后一个字符,其余的每个字符是对应的原字符串中的前一个字符的值加上3.比如"welcome",末尾的字符为"e","welcom"依次家上3后成为"zhofp",故加密后的结果为"ezhofp".程序由用户任意输入一个字符串,加密后输出.

...全文
87 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
gzasholmes 2005-07-20
  • 打赏
  • 举报
回复
mark
cf1944 2005-07-20
  • 打赏
  • 举报
回复
不好意思,第一次发贴,下次会多放些分的...
98star 2005-07-20
  • 打赏
  • 举报
回复
string strT1="abcdef";
string strT2="";
strT2+=strT1[strT1.Length-1];
for(int i=0;i<strT1.Length-1;i++)
{
strT2+=((char)(strT1[i]+3)).ToString();
}
Console.WriteLine(strT2);
cf1944 2005-07-20
  • 打赏
  • 举报
回复
谢谢了......我去看看怎么结帐先.
lovvver 2005-07-20
  • 打赏
  • 举报
回复
创建一个Console Application(控制台程序):把代码覆盖,Ctrl+F5(或F5)即可。

using System;

namespace Encrypt
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Console.WriteLine ("Pleae input a string to encrypt:"+'\n');
string _Input = Console.ReadLine ();
string _Output = _Input[_Input.Length -1].ToString();
string _In = _Input.Substring (0,_Input.Length -1);

for(int i = 0;i<_In.Length;i++)
{
int res = Convert.ToInt16(_In[i])+3;
_Output += Convert.ToChar (res).ToString();
}
Console.WriteLine("Encrypted string:"+_Output+'\n');
}
}
}
Werdong 2005-07-20
  • 打赏
  • 举报
回复
string str = "welcome";

string strOut = string.Empty;
for( int i=0; i<str.Length; i++ )
{
if( i != str.Length - 1 )
{
strOut += ( char)( (int)str[i] + 3 );
}
else
{
strOut = ( char)( (int)str[i] + 3 ) + strOut;
}
}
cf1944 2005-07-20
  • 打赏
  • 举报
回复
还是得不到答案..能把主要的构造函数写出来给我看看吗?
Nintiger 2005-07-20
  • 打赏
  • 举报
回复
char 和 数字可以相互转换的,如果你有A+1那就是B了,以此类推
cf1944 2005-07-20
  • 打赏
  • 举报
回复
各位兄弟姐妹..帮帮我吧
cf1944 2005-07-20
  • 打赏
  • 举报
回复
我对很多东西还是混乱的

110,500

社区成员

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

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

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