之前看反射那一章,真把个人看郁闷了。不巧的是,看到很多业内人士的专业博客说,不会这个也搞了几年的项目开发。哎。顿时打消了学习这个知识的念头。不过,挺巧的是,今天又遇到了一个讲这个内容的章节,只不过内容更具体了。
这样一个动态调用的程序,貌似实现了一个编译器的功能。在Textbox里写上代码,能在程序下方看到编译结果。有趣的是,当代码出错的时候,能在程序中看到错误信息:
//核心代码
public string ComplieAndRun(string input,out bool hasError)
{
CompilerResults cResults = null;
string returnData = null;
[...]
有这样一道题:将一个数的末位,放到首位,使得结果是原数的2倍,求这个数。如:21,转换后,变成12,12不是21的2倍,不符合条件。寻找符合条件的答案,乍一想,可能最难的地方是不知道他是一个几位数。这道题是我从柳大侠的博客上剽窃来的一道题,当初人家是用心算给出的结果。很出乎我意料的是,他的答案居然貌似是正确,并且答案的字面让我很震撼:是一个18位数。
我很纳闷,并有些痛苦的感叹。但很快的我决定写一个程序来代替我思考这样一道算术游戏。废话不多说,上代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.IO;
namespace mathGame
{
class findTheNumber
{
static void Main(string[] args)
{
findTheNumber f = new findTheNumber();
f.showTheAnswer();
}
/**
*分析: 设目标为一个N位数,前N-1位为X,末位为Y
* 则,原数=10x+y;变换后=10^(N-1)*y+x;
* (10x+y)*2=10^(N-1)*y+x
* 19x=(10^(N-1)-2)*y
* 由y为一个一位数,得到10^(N-1)-2为19的倍数,故有:
*
*/
ArrayList getN()
{
int n = 2;
findTheNumber f = new findTheNumber();
BigInteger a = f.mathPower(n-1)-2;
ArrayList al = new ArrayList();
do
{
if (a % 19 == 0)
{
al.Add(n);
}
n++;
a=f.mathPower(n-1)-2;
}while(a.dataLength<100);
return al;
}
BigInteger mathPower(int n)
{
BigInteger i ;
if (n == 0)
return 1;
else
{
return 10 * mathPower(n-1);
}
}
/**
* 通过getN()获取N值后,可得N=18,x=一个17位数*y;
* 满足题目的y值有2-9;
*
*/
void showTheAnswer()
{
BigInteger [...]
这个假期的大部分时间,主要还是宅code。正如上次提到的,我的具体任务是:研制现有资源向移动学习终端系统显示模式的资源转换工具,以及相关的全套技术文档。接单之后,任务很自然的被我分解为:视频、图片和html三个处理模块。(移动学习终端方面,是用的TCL的IOpen来做测试的)。截止至7号凌晨5点16分,整个任务的基本功能全部实现。
图片处理这块,毫无疑问的,我是走了一大圈弯路。 不敢说自己是一个java程序员,但让一个学习了java的人转过头来搞c#,这无疑会带着很复杂的感情。正如Jesse在他的著作里谈的那样:
Java programmers may look at C# with a mixture of trepidation, glee, and resentment. It has been suggested that C# is somehow a “rip-off” of Java. I won’t comment on the religious war between Microsoft and the “anyone but Microsoft” crowd, except to acknowledge that C# certainly learned a great deal from Java. But [...]
最近评论