zoukankan
html css js c++ java
雕虫小技: 给枯燥的 .Net 控制台程序(字符界面)来点儿心跳 (关于退格 '\b' 的使用)
/**/
/*
我写的 Blog 随笔的样例代码绝大部分都是,控制台 Console 程序
里面有一些关于"字符界面"的小技巧,都挺简单的,再次提炼出来,废话不多说了!
都是雕虫小技,见笑:
《给枯燥的 .Net 控制台程序来点儿心跳 (关于退格 '\b' 的使用)》
Java 同理
*/
public
class
Class1
{
public
static
bool
b;
//
结束条件
static
void
Main(
string
[] args)
{
System.Console.WriteLine(
"
测试1: 直接等待 n = 199 次循环
"
);
Wait(
199
);
System.Console.WriteLine(
"
\n\n测试2: 等待结束条件: b == true
"
);
//
主程序 开始
b
=
false
;
new
System.Threading.Thread(
new
System.Threading.ThreadStart(DoWait)).Start();
//
监视线程: 显示滚动计数器
//
以下是耗时的主程序
System.Threading.Thread.Sleep(
5
*
1000
);
//
主程序耗时 5 秒
b
=
true
;
//
主程序 结束
System.Console.WriteLine(
"
\n主程序耗时 5 秒
"
);
}
private
static
void
Wait(
int
Count)
{
System.Console.Write(
"
在进行第
"
);
string
bs
=
""
;
//
用于记录上次的位数
string
s
=
""
;
for
(
int
i
=
0
; i
<
Count
+
1
; i
++
)
{
s
=
System.DateTime.Now.ToString();
System.Threading.Thread.Sleep(
10
);
//
10/1000 second
System.Console.Write(bs
+
"
\b\b\b
"
+
i
+
"
次,
"
+
s);
bs
=
new
string
(
'
\b
'
, Digits(i)
+
s.Length
+
1
);
//
19 为日期时间字符串长度, 1 是 ","
}
}
private
static
void
DoWait()
{
Wait(
ref
b);
//
由委托调用的真正函数
}
private
static
void
Wait(
ref
bool
Flag)
//
Flag 可在其他线程改
{
System.Console.Write(
"
正在进行第
"
);
int
i
=
0
;
string
bs
=
""
;
string
s
=
""
;
while
(
!
Flag)
{
//
System.Threading.Thread.Sleep(1000);
//
1 second
s
=
System.DateTime.Now.ToString();
System.Console.Write(bs
+
"
\b\b\b
"
+
i
+
"
次,
"
+
s);
bs
=
new
string
(
'
\b
'
, Digits(i)
+
s.Length
+
1
);
//
19 为日期时间字符串长度, 1 是 ","
i
++
;
}
}
static
int
Digits(
int
n)
//
数字所占位数
{
n
=
System.Math.Abs(n);
n
=
n
/
10
;
int
i
=
1
;
while
(n
>
0
)
{
n
=
n
/
10
;
i
++
;
}
return
i;
}
}
查看全文
相关阅读:
POJ2723 Get Luffy Out解题报告tarjan+2-SAT+二分
poj2186Popular Cows+tarjan缩点+建图
KMP模板
洛谷P1939【模板】矩阵加速(数列)+矩阵快速幂
矩阵快速幂模板
codeforce#483div2D-XOR-pyramid+DP
codeforce#483div2C-Finite or not?数论,GCD
codeforce978C-Almost Arithmetic Progression+暴力,枚举前两个数字的情况
codeforce440C-Maximum splitting-规律题
LuoGu-P2863牛的舞会The Cow Prom[tarjan 缩点模板]
原文地址:https://www.cnblogs.com/Microshaoft/p/163498.html
最新文章
模板
洛谷
洛谷
hdu 3530 "Subsequence" (单调队列)
The 16th Zhejiang Provincial Collegiate Programming Contest Sponsored E.Sequence in the Pocket(思维题)
Codeforces Round #551 (Div. 2)
Codeforces Round #554 (Div. 2) C. Neko does Maths(GCD(a,b) = GCD(a,b-a))
Codeforces Round #554 (Div. 2) B. Neko Performs Cat Furrier Transform(思维题+log2求解二进制位数的小技巧)
Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array(动态规划.递推)
Educational Codeforces Round 63 (Rated for Div. 2)
热门文章
hdu 4542 "小明系列故事——未知剩余系" (反素数+DFS剪枝)
poj 2886 "Who Gets The Most Candies?"(树状数组)
复习+dfs
CodeForces-768B-Code For 1+DFS类似线段树思想
Codeforces Round #465 &935C. Fifa and Fafa计算几何
HDU
Educational Codeforces Round 43 E&976E. Well played! 贪心
Codeforces Round #480 (Div. 2)980C Posterized+分组类贪心
Educational Codeforces Round 44#985DSand Fortress+二分
POJ-2153Colored Sticks解题报告+欧拉回路,字典树,并查集;
Copyright © 2011-2022 走看看