【发布时间】:2017-06-11 12:32:08
【问题描述】:
我编写了一个简单的程序来查找string 的最小排列,它在字典上大于当前排列。但是,编译器会发出错误
ERROR CS1003 Syntax error, ':' expected* ".
我使用 VS 2015(更新 3),每当我编译这个程序(这在语法上似乎是正确的)时,我都会遇到上述错误。
这个程序有语法错误吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
const string a = "ABCDEFG";
//var u = FFG(a);
//var t = int.Parse(Console.ReadLine());
//for (int i = 0; i < t; i++)
//{
// Console.WriteLine(FFG(Console.ReadLine()));
//}
string u2 = a;
string u = a;
do
{
//***The follownig line meets Error***
Console.WriteLine(u + $"{String.Compare(u, u2) > 0 ? true:false}");
} while ((u = FFG(u)) != "no answer");
Console.ReadLine();
}
static string FFG(string ss)
{
var s = ss.ToCharArray();
int i = s.Length - 1;
while (i >= 1 && s[i] <= s[(i--) - 1])
{ }
if (i == 0 && s[0] >= s[1])
return "no answer";
int j = s.Length - 1;
while (s[i] >= s[(j--)])
{ }
j++;
swap(s, i, j);
int t = i + 1, tt = s.Length - 1;
if (j - i >= 2)
while (t < tt)
{
//if (t == j)
// t++;
//if (tt == j)
// tt--;
swap(s, t, tt);
t++; tt--;
}
return new string(s);
}
static void swap<T>(T[] array, int i, int j)
{
T k = array[i];
array[i] = array[j]; array[j] = k;
}
}
【问题讨论】:
标签: c# compiler-errors