由於反转的概念在我前面的文章已提到~ 所以这边就不多做说明~
简单来说~ 就是将字串"123" ~ 变成 "321" 或将整数-1234 变成-4321
学习目标: C# Reverse 实务
学习难度: ☆☆☆
字串反转
using System;
namespace ConsoleApp1
{
class MainProgram
{
static string Reverse(string input)
{
char[] Array = input.ToCharArray();//将string塞入CharArray
string output = String.Empty;
for (int i = Array.Length - 1; i >= 0; i--)
{
output += Array[i];
}
return output;
}
static void Main()
{
string input = Console.ReadLine();
Console.WriteLine(Reverse(input + "\n"));
}
}
}
整数反转
using System;
namespace ConsoleApp1
{
class MainProgram
{
static int Reverse(int input)
{
int output = 0;
bool negative = false;
if (input == 0)
{
return 0;
}
else if (input > 0)
{
negative = false;
}
else if (input < 0)
{
input = Math.Abs(input);
negative = true;
}
while (input > 0) /*这个回圈是Reverse的核心*/
{
output = output * 10 + input % 10;
input /= 10;
}
if (negative == true)
{
output *= -1;
}
return output;
}
static void Main()
{
Console.WriteLine(Reverse(-6532));
}
}
}
参考资料:
一、迁移式学习(Transfer Learning) 动机 我们在做监督式学习(Supervised...
前言 做到现在会发现每个ViewController内的程序码都一大堆,有画面元件,有逻辑,有Mod...
可以先把下面的范例载下来,并执行app.py: https://github.com/wilsons...
一直很犹豫要不要把今天这篇和昨天那篇合在一起,最後还是分开了( ̄3 ̄)╭,觉得分开整体看起来比较统一...
待完成 ...