编程题、面试题:
1、leecode
2、牛客网
编程题、面试题:
1、leecode
2、牛客网
NNYNNY
console.writeline("1\n\t2\n3");
if-else语句多条件判断
例:if(score ≥ 90)//判断是否大于90,若是则评级a
{
Console.WriteLine("a")
}
if(score≥70 && score ≤ 89)
{
Console.WriteLine("b")
}
if(score≥60 && score ≤ 69)
{
Console.WriteLine("c")
}
此时各段IF判断为同级,同时判断
例2:
if(score ≥ 90)
{
Console.WriteLine("a")
} else if (score ≥ 70)//当不满足大于90时,判断是否大于70,是则评级b
{
Console.WriteLine("b")
} else if (score ≥ 60)//当不满足大于70时,判断是否大于60,是则评级c
{
Console.WriteLine("c")
}
else //当前面条件局部满足时,判断d
{
Console.WriteLine("d")
}
IF条件语句
1.用于判断是否达成条件,并运行相应的程序。例if(age≤16) {
//当条件满足时执行"{}"中的内容
Console.WriteLine("可以进入")
}
else //当不满足时执行else的代码
Console.WriteLine("年龄太大")
见名之意
using syste
console.调用某一个类
using System;//注释:引入命名空间
namespace _001_开始
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
string str = Console.ReadLine();
string[] str.Array = str.Split(" ");
int [] intArray = new int
逻辑运算符
0.bool函数,用于判断运算结果为Ture 或者 False
1.逻辑运算符一共有三类,逻辑与“&&”;逻辑或“||”;以及逻辑非“!”
2.“&&”逻辑与代表需要同时两个条件时,为Ture,例:(A&&B)即条件A与B都打成时为Ture;
3.“||”逻辑或代表直须满足一个条件,为Ture,例:(A||B)即满足条件A或条件B时,为Ture
4.“!”逻辑非则是逆转操作数的逻辑状态,如果条件为Ture则逻辑非运算符使其为False。例:bool c = !(4 < 7);运算为false,但是逻辑非使其运算结果为Ture
世界上语言的排行榜
tiobe
自增自减运算符:
例:int a = 5;
a++;
a++;
console.writeline(a);
输出结果为7,即“a++”= a+1,或理解为自身增加1(也可书写为++a)
同理推断a--=a-1
a++与++a再单独代码书写时无区别,但是若书写在一个运算当中,则两者有所区别
例:
int a = 5;
int b = a++;
Console.WriteLine(a)(此为先赋值再自增,b=6,a=5)
而int b = ++a则为先自增再赋值(b=6,a=6)
若是单独Console.WriteLine(a++),则里面的a++不运算;
但若是
Console.WriteLine(a++);
Console.WriteLine(a);
则输出结果为5和6
string[] s = (Console.ReadLine()).Split(' ');
可以这样连续输入数字并转成字符数组
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _001_开始
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.ReadKey();
}
}
}
小于两千的值 因此输出的k 应该是k-1
int total = 0;
for(int i = 1; i< 11; i++){
int temp = 1;
for (int j = 1; j < i + 1; j ++){
temp =temp * j;
}
//i!
total = total + temp;
}
Console.WriteLine(total);
递归的写法:
static int F1(int n )
{
if(n ==1)
return 1;
int result = n *F1(n-1);
return result;
}
static int F2(int n )
{
if(n ==1)
return 1;
int result =F2(n-1)+F1(n);// 相加 ,加上累乘
return result;
}
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
int m = n;
string s = "";
while (n != 0)
{
s += Convert.ToString(n % 10);
n /= 10;
}
if (Convert.ToString(m) == s)
{
Console.WriteLine("您输入的数{0}是回文数", n);
}
else { Console.WriteLine("您输入的数不是回文数"); }
}
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
string s = "";
while (n != 0)
{
s += Convert.ToString(n % 10);
n /= 10;
}
Console.WriteLine(Convert.ToInt32(s));
}
首先是通过count 来存放 因子的个数 数量
之后在函数里for循环 若找到因子
if ( number % i ==0)
count++;
定义一个数组用来,其长度为number的数量,之后找到了因子就放到数组里面,来一个数就放进去
而数组具体的位置存放的数则需要index
从而知道数放在哪个位置,来一个数就让index++
int [] array = new int [count];
int index = 0;
for(int i =1;i< number; i++)
{
if(number % i ==0)
array[index] = i;
index ++;
}
return array;
赋值运算符
1.a+=b,即为a=a+b,-=,/=,*=,以及其他同格式运算都是相同逻辑
数学运算符
1.除常用的四种数学运算外,还有取模(求余),通常用于整数运算,用于小数时容易出现不精确的问题;
2.当运算的数字均为整数时则可以用int作输出,但如果运算的数字中有一个或以上的数字是小数是(如10.0)则输出要用double而非int