**1.**while(1 -eq 1){
[char]
a
=
R
e
a
d
−
H
o
s
t
(
"
请
输
入
一
个
字
符
"
)
[
i
n
t
]
a = Read-Host("请输入一个字符") [int]
a=Read−Host("请输入一个字符")[int]b = [char]$a
if((
b
−
g
e
48
)
−
a
n
d
(
b -ge 48) -and (
b−ge48)−and(b -le 57)){
Write-Output(“这是一个数字”)
}elseif((
b
−
g
e
65
)
−
a
n
d
(
b -ge 65) -and (
b−ge65)−and(b -le 90)){
Write-Output(“这是一个大写字母”)
}elseif((
b
−
g
e
97
)
−
a
n
d
(
b -ge 97) -and (
b−ge97)−and(b -le 122)){
write-output(“这是一个小写字母”)
}else{
Write-Output(“这是一个特殊字符”)
}
if($b -eq 101){
break
}
}
2.[string]$name = Read-Host(“请输入一个字符串”)
p
,
p,
p,q,
r
,
r,
r,s = 0,0,0,0
[char[]]$names =
n
a
m
e
.
T
o
C
h
a
r
A
r
r
a
y
(
)
f
o
r
(
name.ToCharArray() for(
name.ToCharArray()for(j = 0; $j -le
n
a
m
e
s
.
L
e
n
g
t
h
;
names.Length ;
names.Length;j++){
[int]$a = $names[$j]
if(($a -ge 48) -and ($a -le 57)){
$p++
}elseif(($a -ge 65) -and ($a -le 90)){
$q++
}elseif(($a -ge 97) -and ($a -le 122)){
$r++
}else{
$s++
}
}
Write-Output(“有{0}个数字,有{1}个大写字母,有{2}个小写字母,有{3}个字符”-f p , p, p,q, r , r, r,s)
3.
c
=
1
f
o
r
(
c = 1 for(
c=1for(i=100 ;
i
−
l
t
999
;
i -lt 999;
i−lt999;i++){
c
+
=
c+=
c+=i
[string]$c =
i
[
i
n
t
]
i [int]
i[int]b1 =
c
.
S
u
b
s
t
r
i
n
g
(
0
,
1
)
[
i
n
t
]
c.Substring(0,1) [int]
c.Substring(0,1)[int]b2 =
c
.
s
u
b
s
t
r
i
n
g
(
1
,
1
)
[
i
n
t
]
c.substring(1,1) [int]
c.substring(1,1)[int]b3 =
c
.
s
u
b
s
t
r
i
n
g
(
2
,
1
)
i
f
(
(
c.substring(2,1) if((
c.substring(2,1)if((b1*
b
1
∗
b1*
b1∗b1+
b
2
∗
b2*
b2∗b2*
b
2
+
b2+
b2+b3*
b
3
∗
b3*
b3∗b3) -eq KaTeX parse error: Expected '}', got 'EOF' at end of input: …utput("水仙花: "+c)
}
}
4.[string]
s
t
r
=
R
e
a
d
−
H
o
s
t
"
请
输
入
一
个
字
符
串
"
[
i
n
t
]
str = Read-Host "请输入一个字符串" [int]
str=Read−Host"请输入一个字符串"[int]a =
s
t
r
.
L
e
n
g
t
h
f
o
r
(
str.Length for(
str.Lengthfor(i = 1;$i -le
a
;
a;
a;i++){
[string]$char_tem =
s
t
r
.
S
u
b
s
t
r
i
n
g
(
str.Substring(
str.Substring(i-1,1)
if($char_tem -notmatch “[0-9.]”){
Write-Output(“不能被转换为一个有效数字”)
}elseif ( $i -eq $a){
Write-Output “你输入的字符串可以转换为一个有效的数字”
}
}
**5.**for($q = 1;
q
−
l
e
9
;
q -le 9;
q−le9;q++){
for($p = 1; $p -le
q
;
q;
q;p++){
Write-Host(" {0} * {1} = {2} " -f
q
,
q,
q,p,(
q
∗
q*
q∗p)) -NoNewline
}
Write-Output("")
}
**6.**for(
b
=
0
;
b = 0;
b=0;b -le 1000;KaTeX parse error: Expected '}', got 'EOF' at end of input: b++){ for(a =0;
a
−
l
e
1000
;
a -le 1000;
a−le1000;a++){
if((
a
∗
a*
a∗a)-eq(KaTeX parse error: Expected '}', got 'EOF' at end of input: … for(C = 0;
c
−
l
e
1000
;
c -le 1000;
c−le1000;c++){
if((
c
∗
c*
c∗c)-eq(KaTeX parse error: Expected '}', got '#' at position 30: … #̲Write-Output(b)
}
}
}
}
}Write-Output($b)
7.[string]$ml = “网络空间安全”
$mq = $ml.Substring(2,4)
$ma =
m
l
.
S
p
l
i
t
(
ml.Split(
ml.Split(mq)
$mb = $ml.Remove(0,1).Split(“间安全”)
$mc = $ml.Remove(0,2).Split(“安全”)
$md = $ml.Remove(0,3).Split(“全”)
$mf =
m
l
.
R
e
m
o
v
e
(
0
,
4
)
w
r
i
t
e
−
h
o
s
t
(
ml.Remove(0,4) write-host(
ml.Remove(0,4)write−host(ma ,
m
b
,
mb ,
mb,mc ,
m
d
,
md ,
md,mf) -NoNewline
8.
n
u
m
=
3
,
65
,
22
,
102
,
4
f
o
r
(
num=3,65,22,102,4 for(
num=3,65,22,102,4for(i=0;$i -lt
n
u
m
.
L
e
n
g
t
h
;
num.Length;
num.Length;i++){
for(
j
=
0
;
j=0;
j=0;j -lt
n
u
m
.
L
e
n
g
t
h
−
num.Length-
num.Length−i-1;KaTeX parse error: Expected '}', got 'EOF' at end of input: …+){ if(num[$j] -lt
n
u
m
[
num[
num[j+1]){
$max =
n
u
m
[
num[
num[j+1]
n
u
m
[
num[
num[j+1] =
n
u
m
[
num[
num[j]
n
u
m
[
num[
num[j] = KaTeX parse error: Expected 'EOF', got '}' at position 15: max }̲ } } Write-…num)
**9.**for($b = 2 ; $b -lt 1000 ; KaTeX parse error: Expected '}', got 'EOF' at end of input: b++){ for(a = 2 ; $a -le $b ; KaTeX parse error: Expected '}', got 'EOF' at end of input: …){ if((b % $a) -eq 0){
break;
}
}
if($a -eq $b){
Write-Output($b)
}
}
10.<#for(
a
=
1
;
a = 1 ;
a=1;a -le 5;KaTeX parse error: Expected '}', got 'EOF' at end of input: a++){ for(b = 1;$b -le
a
;
a;
a;b++){
Write-Host("*")-NoNewline
}
Write-Host("")
}#>
[int]
l
i
n
e
=
R
e
a
d
−
H
o
s
t
(
"
请
输
入
行
数
"
)
f
o
r
(
line=Read-Host("请输入行数") for(
line=Read−Host("请输入行数")for(i =1; $i -le $line; KaTeX parse error: Expected '}', got 'EOF' at end of input: i++){ for(j=1; $j -le
l
i
n
e
−
line-
line−i;
j
+
+
)
W
r
i
t
e
−
H
o
s
t
(
"
"
)
−
N
o
N
e
w
l
i
n
e
f
o
r
(
j++){ Write-Host(" ") -NoNewline } for(
j++)Write−Host("")−NoNewlinefor(j=1;
j
−
l
e
2
∗
j -le 2*
j−le2∗i-1; $j++){
Write-Host("*") -NoNewline
}
Write-Host("")
}