如何使用 T-SQL 在 SQL Server 中进行查询以返回列值中第一个字母/字符的计数?
我一直在尝试使用这个c ++程序按字母顺序排序5个名称:
#include <iostream>
#include <cstring>
#include <conio.h>
using namespace std;
int main()
{
char names[5][100];
int x,y,z;
char exchange[100];
cout << "Enter five names...\n";
for(x=1;x<=5;x++)
{
cout << x << ". ";
cin >> names[x-1];
}
getch();
for(x=0;x<=5-2;x++)
{
for(y=0;y<=5-2;y++)
{
for(z=0;z<=99;z++)
{
if(int(names[y][z])>int(names[y+1][z]))
{
strcpy(exchange,names[y]);
strcpy(names[y],names[y+1]);
strcpy(names[y+1],exchange);
break;
}
}
}
}
for(x=0;x<=5-1;x++)
cout << names[x];
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我分别进入厄尔,唐,克里斯,比尔和安迪,我得到这个:
AndyEarlDonChrisBill
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我我的程序有什么问题吗?
我需要知道的是如何找到数组内字符串的长度。我还想知道如何找到数组中按字母顺序排列第一个的字符串。
顺序应该是这样的.
AZ,AA-AZ,BA-BZ,CA-CZ,.......,ZA-ZZ
在ZZ之后它应该从AAA开始.
然后是AAA到ZZZ再到AAAA到ZZZZ等等.
这个序列非常类似于Excel表格.
编辑:添加了我的代码
private void SequenceGenerator()
{
var numAlpha = new Regex("(?<Numeric>[0-9]*)(?<Alpha>[a-zA-Z]*)");
var match = numAlpha.Match(txtBNo.Text);
var alpha = match.Groups["Alpha"].Value;
var num = Convert.ToInt32(match.Groups["Numeric"].Value);
lastChar = alpha.Substring(alpha.Length - 1);
if (lastChar=="Z")
{
lastChar = "A";
txtBNo.Text = num.ToString() + "A" + alpha.Substring(0, alpha.Length - 1) + lastChar;
}
else
{
txtBNo.Text = num.ToString() + alpha.Substring(0, alpha.Length - 1) + Convert.ToChar(Convert.ToInt32(Convert.ToChar(lastChar)) + 1);
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我所做的.但是,我知道这是错误的逻辑. …
alphabetical ×4
string ×2
arrays ×1
c# ×1
c++ ×1
java ×1
sequences ×1
sequencing ×1
sorting ×1
sql-server ×1
t-sql ×1