没人帮忙我就不去吃饭了,,
( thinkingforever(海) 我现在手头上没有算法的书啊)
( thinkingforever(海) 我现在手头上没有算法的书啊)
解决方案 »
- 关于form刷新问题
- 类与类间方法的调用
- WinForm中如何实类似word插拖功能?
- 这样的2个表联合查询的sql语句如何写啊?(急)谢谢大家了!
- 最近在项目里遇到一个无窗口打印报表的问题,希望和大家交流下!
- 为什么输出结果不是1
- SQL Server 2005 无法连接到 MSDE 2000,高手相助
- 如何实现DataGrid中列的标头双行显示??????????????
- webBrowser 按钮单击事件的时候怎么获取按钮的id或者dom
- c#如何调用outlook邮箱发送HTML表格拼接数据库
- 偷偷的问几个丢人的问题!(Together)
- HttpUtility,在哪个名字空间,救急呀.............
2.(转发 AhBian(阿扁))using System;namespace YourNameSpace
{
/// <summary>
/// 此静态类用来转换 decimal 类型的货币值为汉字字符串
/// 目前不能被继承,仅提供两个公开静态方法。
/// 方法 ToJianti 的结果是简体字符
/// 方法 ToFanti 的结果是繁体字符,内部实际调用的还是 ToJianti 方法
/// </summary>
public sealed class DecimalCharacterConvertor
{
private DecimalCharacterConvertor()
{
}//转换为简体
public static string ToJiantiReading(decimal decNumber)
{
string strResult = "";
if (decNumber != 0m)
strResult = TransPositive (Math.Abs (decNumber));
else
return strResult;
if (decNumber < 0m && strResult != "")
{
strResult = "负" + strResult;
}
return (strResult == "") ? strResult:("¥" + strResult);
}
//转换调用ToJianti后的值为繁体
public static string ToFantiReading(decimal decNumber)
{
string strResult = "";
string strJianti = ToJiantiReading (decNumber);
if (strJianti == "" || strJianti == null)
return strResult;for (int i = 0; i < strJianti.Length ;i++)
{
#region Switch
switch (strJianti.Substring (i, 1))
{
case "零":
strResult += "零";
break;
case "一":
strResult += "壹";
break;
case "二":
strResult += "贰";
break;
case "三":
strResult += "叁";
break;
case "四":
strResult += "肆";
break;
case "五":
strResult += "伍";
break;
case "六":
strResult += "陆";
break;
case "七":
strResult += "柒";
break;
case "八":
strResult += "捌";
break;
case "九":
strResult += "玖";
break;
case "十":
strResult += "拾";
break;
case "百":
strResult += "佰";
break;
case "千":
strResult += "仟";
break;
default:
strResult += strJianti.Substring (i, 1);
break;
}
# endregion
}return strResult;
}
//转换正数部分
private static string TransPositive (decimal decNumber)
{
string strResult = "";
string strNumber = decNumber.ToString("F2");
string strIntg = strNumber.Substring( 0 , strNumber.IndexOf("."));
string strFrac = strNumber.Substring( strNumber.IndexOf('.') + 1 , 2);for (int i = 0 ; i < strIntg.Length ; i++)
{
strResult += TransDigit(strIntg[i]) + TransUnit (strIntg.Length - i);
}
strResult += TransDigit(strFrac[0]) + "角" + TransDigit(strFrac[1]) +"分";//去掉无意义的单位值。
strResult = strResult.Replace("零分", "零");
strResult = strResult.Replace("零角", "零");
strResult = strResult.Replace("零十", "零");
strResult = strResult.Replace("零百", "零");
strResult = strResult.Replace("零千", "零");//合并连续重复的多个零为一个零。
while (strResult.IndexOf ("零零") != -1)
{
strResult = strResult.Replace("零零", "零");
}//对"零元"及"零兆"进行处理:直接去掉无意义的零
strResult = strResult.Replace("零兆", "兆");
strResult = strResult.Replace("零元", "元");//对"零万"进行处理。须依据前一个字符值。
int index = strResult.IndexOf ("零万");
while(index != -1)
{
if (strResult.Substring (index-1, 1) != "亿" && strResult.Substring (index-1, 1) != "兆")
strResult = strResult.Remove (index, 1);
else
strResult = strResult.Remove (index + 1, 1);
index = strResult.IndexOf ("零万");
}//合并连续重复的多个零为一个零。
while (strResult.IndexOf ("零零") != -1)//检测有无“零零”这样的字符串存在。
{
strResult = strResult.Replace("零零", "零");
}int index1 = strResult.IndexOf ("零亿");
while(index1 != -1 && index1 != 0)
{
if (strResult.Substring (index1-1, 1) != "兆")
strResult = strResult.Remove (index1, 1);
else
strResult = strResult.Remove (index1 + 1, 1);
index1 = strResult.IndexOf ("零亿");
}//合并连续重复的多个零为一个零。
while (strResult.IndexOf ("零零") != -1)//再一次执行。因为上一个while语句处理后,可能会出现新的“零零”。
{
strResult = strResult.Replace("零零", "零");
}//若末位为"零",替换成“整”
if (strResult.EndsWith ("零"))
{
strResult = strResult.Remove(strResult.Length - 1, 1);
strResult += "整";
}//若以"元零"开始,去掉
if (strResult.StartsWith ("元零"))
{
strResult = strResult.Remove(0, 2);
}//若以“元”开始,去掉
if (strResult.StartsWith ("元"))
{
strResult = strResult.Remove(0, 1);
}return strResult;
}
//转换单个数字
private static string TransDigit (char chrDigit)
{
string strResult = "";
switch (chrDigit)
{
case '0':
strResult = "零";
break;
case '1':
strResult = "一";
break;
case '2':
strResult = "二";
break;
case '3':
strResult = "三";
break;
case '4':
strResult = "四";
break;
case '5':
strResult = "五";
break;
case '6':
strResult = "六";
break;
case '7':
strResult = "七";
break;
case '8':
strResult = "八";
break;
case '9':
strResult = "九";
break;
}
return strResult;
}//转换整数单位
private static string TransUnit (int intSeq)
{
string strResult = "";
switch (intSeq % 4)
{
case 1:
#region switch statement
switch ( intSeq )
{
case 1:
strResult = "元";
break;
case 5:
strResult = "万";
break;
case 9:
strResult = "亿";
break;
case 13:
strResult = "万";
break;
case 17:
strResult = "兆";
break;
case 21:
strResult = "万";
break;
case 25:
strResult = "亿";
break;
case 29:
strResult = "万";
break;
}
#endregion
break;
case 2:
strResult = "十";
break;
case 3:
strResult = "百";
break;
case 0:
strResult = "千";
break;
}
return strResult;
}
}}3:写一个函数计算当参数为n(n可能很大)时的值 1-2+3-4+5-6+7.....+n(1-2)+(3-4)+(5-6)+(7-8).....+n n为奇数,偶数两种情况
Dim n As Integer = 15
Dim m As Integer = 89
Do
m = m - n
Loop Until (m - n) < n
Dim sNo As Integer = m - n
using System;namespace Qustion
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
//输出最后一个序号,实际上d[]里是所有的序号。
public static int GetOrder(int n,int m)
{
int iSum=0;
int iTemp=0;
int id=0;
int[] s=new int[n];
int[] d=new int[n];
for(int i=0;i<n;i++) {s[i]=1;d[i]=0;}
while(d[n-1]==0)
{
iSum+=s[iTemp];
if(iSum==m) {d[id]=iTemp+1;s[iTemp]=0;id++;iTemp++;iSum=0;}
else iTemp++;
if(iTemp==n) iTemp=0;
}
return d[n-1];
}
static void Main(string[] args)
{Console.Write(GetOrder(6,3).ToString());//输出1
Console.Write(GetOrder(5,3).ToString());//输出4
//
// TODO: 在此处添加代码以启动应用程序
//
}
}
}
{
var mynum,result;
if(isNaN(document.all('txtinput').value))
{
alert('对不起,您输入的不是数字');
return false;
}
else
{
if(document.all('txtinput').value==0)
{
alert('对不起,您忘记输入什么了:(');
return false;
}
mynum=parseInt(document.all('txtinput').value);
if(mynum%2==0)
{
result=-mynum/2;
}
else
{
result=-(mynum-1)/2+mynum;
}
document.all('txtinput').value=result;
}
}
高人真多,,嘿嘿,,
啥时候我也能帮别人做题呢,,唉,,感慨ing谢谢大家,,我先试试,,
public static int GetSum(int n)
{
if (n % 2==0) return (-n/2);
else return (n-(n-1)/2);
}
函数返回值即为所求和。
楼主,我也是个新手,大家一起在msdn的平台上交流,进步。
static int test(int n,int sum )
{
if( n == 2)
return sum -1;
else
return test(sum + ((n%2==1)?n:-n) ,n-1);
}
第一:第11行 if(document.all('txtinput').value==0)改为if(document.all('txtinput').value=="")
第二:加一个判断,输入为正数才对:
if mynum<=0;
{
alert('对不起,不能输入负数!');
return false;
}
public string f(int a)
{
string b=a.ToString();
string[] c=new string[]{"零","一","二","三","四","五","六","七","八","九"};
string[] d=new string[]{"","十","百","千","万","十","百","千","亿","十"};
string e="";
string f="";
string h,g;
for(int i=0;i<b.Length;i++)
{
for(int j=0;j<10;j++)
{
if(Convert.ToInt16(b.Substring(i,1))==j)
{
e+=c[j];
break;
}
}
}
for(int i=b.Length,j=0;i>0;i--,j++)
{
h=e.Substring(i-1,1)+d[j];
g=f;
f=h;
f+=g;
}
return f;
}
没有去掉“零”。