1.basic string Դ??
2.C++ä¸ç¨basic_string <char>::size_type ä¸int
3.全排列VB源代码
basic string Դ??
用vb.net做的校友录……(附所有源代码)
来源:不详 作者 佚名 点击数: 录入时间:-- ::
想必大家都上过校友录吧,里面的功能虽然不是很强大,但是为我们这些毕业之后各奔西东的学子来说,到真是提供了一个好的聚集点,下面是我用vb.net做的校友录,当然也不能说是通达信加速均线源码校友录了,只能说是我们班的学友录了:)不过只要你掌握了这种编程思想,校友录就不在话下了。这里我将重点谈一下关于管理员权限赋予。
以前有这个想法的时候,难就难在管理员身份的赋予上,开始想如果一般用户在被提升为管理员之后,疯狂解析源码我可以把他的信息转到另外一个表中,以后登陆的时候先检查manage表中是否有他就行了,这种办法我已经实现了,是不是有些笨……可是正在我要正式开工的时候,一个想法突然冒了出来,是什么呢?呵呵,就是在数据库中再增加一个字段了如果是第一次注册就让这个字段item(int)的值为0,要是被提升之后就update为1,班级创始人呢?当然了,在他申请时付给他一个班级id,然后先判断班级id为这个已经注册的ecmobile 4.0 源码人信息条数是否为0,如果是,那么就付给他item=2好了。下面的代码中,我没有实现这个功能,因为我做的是班友录的,当然了,我就是管理员喽:)
在这里,我使用的是checkboxlist(两个),一个用来转换数据(visibe=fause),一个用来显示数据,还有一个checkbox用来写全部选中的jdk源码编译事件。当然了还有两个按钮事件,一个是用来提升为管理员的,一个是用来降级为一般用户的,这两个按钮在判断为一般用户时
enable都是为fause的,只有当判断登录为管理员时才为true。当然了,如果你是班级创始人,是不可能被降级的:)
这里用来显示信息的我用的是一个datagrid,当判断为非管理员时,删除栏的visible将为fause,为管理员的maven 项目源码时候,才为true,也就是说只有管理员才可以删除信息。而不是注册的用户是不能发言的所有的按钮控件的enable将都为fause。
代码如下:board.aspx
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="boaman.aspx.vb" Inherits="_re1.boaman"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title></title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="javascript" name="vs_defaultClientScript">
<meta content="/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body background="image/bg.gif" MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:checkbox id="yourcheck" style="Z-INDEX: ; LEFT: px; POSITION: absolute; TOP: px" runat="server" Text="全部选中" AutoPostBack="True" ForeColor="SaddleBrown" Font-Bold="True"></asp:checkbox>
<asp:button id="Button1" style="Z-INDEX: ; LEFT: px; POSITION: absolute; TOP: px" runat="server" Text="提升为管理员" Height="px" Width="px" BackColor="Gainsboro" BorderColor="Lavender" BorderWidth="2px" BorderStyle="Outset"></asp:button>
<asp:button id="Button2" style="Z-INDEX: ; LEFT: px; POSITION: absolute; TOP: px" runat="server" Text="降级为一般用户" Height="px" Width="px" BackColor="Gainsboro" BorderColor="Lavender" BorderWidth="2px" BorderStyle="Outset"></asp:button>
<asp:checkboxlist id="CheckBoxList1" style="Z-INDEX: ; LEFT: px; POSITION: absolute; TOP: px" runat="server" Visible="False"></asp:checkboxlist>
<asp:checkboxlist id="mycheck" style="Z-INDEX: ; LEFT: px; POSITION: absolute; TOP: px" runat="server" ForeColor="Navy" Font-Size="X-Small"></asp:checkboxlist>
<asp:label id="Label1" style="Z-INDEX: ; LEFT: px; POSITION: absolute; TOP: px" runat="server" ForeColor="Red" Font-Names="方正姚体">(已注册用户)</asp:label>
<asp:image id="Image1" style="Z-INDEX: ; LEFT: px; POSITION: absolute; TOP: px" runat="server" Height="px" Width="px" ImageUrl="image/re1-1.gif"></asp:image>
<asp:datagrid id="DataGrid1" style="Z-INDEX: ; LEFT: px; POSITION: absolute; TOP: px" runat="server" Height="px" Width="px" BorderColor="#ffcc" AutoGenerateColumns="False" HeaderStyle-Font-Size="9" HeaderStyle-HorizontalAlign="Center" HeaderStyle-ForeColor="red" HeaderStyle-Font-Bold="True">
<Columns>
<asp:HyperLinkColumn ItemStyle-ForeColor="navy" ItemStyle-HorizontalAlign="Center" ItemStyle-Height="" ItemStyle-Font-Size="9" DataNavigateUrlField="stu_id" DataNavigateUrlFormatString="querry.aspx?stu_id={ 0}" DataTextField="stu_id" HeaderText="学号"></asp:HyperLinkColumn>
<asp:BoundColumn ItemStyle-ForeColor="navy" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="" ItemStyle-Font-Size="9" DataField="tel" HeaderText="电话"></asp:BoundColumn>
<asp:BoundColumn ItemStyle-ForeColor="navy" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="" ItemStyle-Font-Size="9" DataField="oicq" HeaderText="OICQ"></asp:BoundColumn>
<asp:BoundColumn ItemStyle-ForeColor="navy" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="" ItemStyle-Font-Size="9" DataField="email" HeaderText="E-mail"></asp:BoundColumn>
<asp:BoundColumn ItemStyle-ForeColor="navy" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="" ItemStyle-Font-Size="9" DataField="point" HeaderText="登录次数"></asp:BoundColumn>
</Columns>
</asp:datagrid>
</form>
</body>
</HTML>
下面是codebehind中的内容:boaman.asp.vb
Imports System.Data
Imports System.Data.SqlClient
Public Class boaman
Inherits System.Web.UI.Page
Protected WithEvents yourcheck As System.Web.UI.WebControls.CheckBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents CheckBoxList1 As System.Web.UI.WebControls.CheckBoxList
Protected WithEvents mycheck As System.Web.UI.WebControls.CheckBoxList
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Image1 As System.Web.UI.WebControls.Image
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Dim conn As SqlConnection = New SqlConnection("server=lixinri;uid=sa;pwd=;database=re1")
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'////////////////////判断是否为过客
If Session("stu_id") = "" Then
Button1.Enabled = False : Button2.Enabled = False
'////////////////////调用check()事件
check()
Else
If Not IsPostBack Then
Dim sql As String = "select * from pwd where stu_id=@stu_id"
Dim comm As SqlCommand = New SqlCommand(sql, conn)
comm.Parameters.Add(New SqlParameter("@stu_id", SqlDbType.Int, 4))
comm.Parameters("@stu_id").Value = Session("stu_id")
Dim dr As SqlDataReader
conn.Open()
dr = comm.ExecuteReader
While dr.Read
If dr.Item("term") = "0" Then
'///////////////////判断是否为一般用户
dr.Close()
Button1.Enabled = False : Button2.Enabled = False
Dim sql_1 As String = "select a.stu_id as stu_id,a.term,b.name as name,b.tel as tel,b.call as oicq,b.point as point,b.email from pwd a,stu_base b where a.stu_id=b.stu_id"
Dim cmd As New SqlCommand(sql_1, conn)
dr = cmd.ExecuteReader
While dr.Read
If dr.Item("term") = "1" Then
mycheck.Items.Add("<u>" & dr.Item("name") & "</u>" & "<font color=darkorange>(管理员)</font>")
ElseIf dr.Item("term") = "2" Then
mycheck.Items.Add("<u>" & dr.Item("name") & "</u>" & "<font color=red>(班级创始人)<font>")
Else
mycheck.Items.Add("<u>" & dr.Item("name") & "</u>")
End If
CheckBoxList1.Items.Add(dr.Item("stu_id"))
End While
Else
'////////////////////判断是否为管理员
dr.Close()
Button1.Enabled = True : Button2.Enabled = True
Dim sql_1 As String = "select a.stu_id as stu_id,a.term,b.name as name,b.tel as tel,b.call as oicq,b.point as point,b.email from pwd a,stu_base b where a.stu_id=b.stu_id"
Dim cmd As New SqlCommand(sql_1, conn)
dr = cmd.ExecuteReader
While dr.Read
If dr.Item("term") = "1" Then
mycheck.Items.Add("<u>" & dr.Item("name") & "</u>" & "<font color=darkorange>(管理员)</font>")
ElseIf dr.Item("term") = "2" Then
mycheck.Items.Add("<u>" & dr.Item("name") & "</u>" & "<font color=red>(班级创始人)<font>")
Else
mycheck.Items.Add("<u>" & dr.Item("name") & "</u>")
End If
CheckBoxList1.Items.Add(dr.Item("stu_id"))
End While
End If
End While
dr.Close()
'////////////////////////取出数据,填充dataset
Dim mysql As String = "select a.stu_id as stu_id,a.term,b.name as name,b.tel as tel,b.call as oicq,b.point as point,b.email from pwd a,stu_base b where a.stu_id=b.stu_id"
comm = New SqlCommand(mysql, conn)
Dim mycomm As SqlDataAdapter = New SqlDataAdapter(mysql, conn)
Dim ds As DataSet = New DataSet()
mycomm.Fill(ds, "base")
DataGrid1.DataSource = ds.Tables("base").DefaultView
DataGrid1.DataBind()
End If
End If
End Sub
'///////////////////////书写check()事件
Sub check()
If Not IsPostBack Then
Dim mysql As String = "select a.stu_id as stu_id,a.term,b.name as name,b.tel as tel,b.call as oicq,b.point as point,b.email from pwd a,stu_base b where a.stu_id=b.stu_id"
Dim comm As New SqlCommand(mysql, conn)
Dim dr As SqlDataReader
conn.Open()
dr = comm.ExecuteReader
While dr.Read
If dr.Item("term") = "1" Then
mycheck.Items.Add("<u>" & dr.Item("name") & "</u>" & "<font color=darkorange>(管理员)</font>")
ElseIf dr.Item("term") = "2" Then
mycheck.Items.Add("<u>" & dr.Item("name") & "</u>" & "<font color=red>(班级创始人)<font>")
Else
mycheck.Items.Add("<u>" & dr.Item("name") & "</u>")
End If
CheckBoxList1.Items.Add(dr.Item("stu_id"))
End While
dr.Close()
Dim mycomm As SqlDataAdapter = New SqlDataAdapter(mysql, conn)
Dim ds As DataSet = New DataSet()
mycomm.Fill(ds, "base")
DataGrid1.DataSource = ds.Tables("base").DefaultView
DataGrid1.DataBind()
End If
End Sub
'/////////////////////填充yourcheck
Private Sub yourcheck_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles yourcheck.CheckedChanged
Dim i As Integer
For i = 0 To mycheck.Items.Count - 1
If yourcheck.Checked Then
mycheck.Items(i).Selected = True
Else
mycheck.Items(i).Selected = False
End If
Next
End Sub
'///////////////////////提升一般用户为管理员
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
conn.Open()
Dim i As Integer
For i = 0 To mycheck.Items.Count - 1
If mycheck.Items(i).Selected Then
Dim sql_1 As String = "update pwd set term=1 where stu_id=@stu_id and term=0"
Dim comm As SqlCommand = New SqlCommand(sql_1, conn)
comm.Parameters.Add(New SqlParameter("@stu_id", SqlDbType.Int, 4))
comm.Parameters("@stu_id").Value = CheckBoxList1.Items(i).Text
comm.ExecuteNonQuery()
End If
Next
Response.Redirect("boaman.aspx")
End Sub
'///////////////////////降级管理员为一般用户
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
conn.Open()
Dim i As Integer
For i = 0 To mycheck.Items.Count - 1
If mycheck.Items(i).Selected Then
Dim sql_1 As String = "update pwd set term=0 where stu_id=@stu_id and term=1"
Dim comm As SqlCommand = New SqlCommand(sql_1, conn)
comm.Parameters.Add(New SqlParameter("@stu_id", SqlDbType.Int, 4))
comm.Parameters("@stu_id").Value = CheckBoxList1.Items(i).Text
comm.ExecuteNonQuery()
End If
Next
Response.Redirect("boaman.aspx")
End Sub
End Class
当然了,这里面还有好多不足的地方,恳求高手批评指正。
校友录还有一些其它的功能就很简单了,这里就不再探讨了。
C++ä¸ç¨basic_string <char>::size_type ä¸int
basic_string<char>::size_type å°±æ¯ungisned intï¼è¿ä¸ªä½ å¯ä»¥çæºç
æ以就æ¯unsigned intåintçåºå«
为äºä¸å¨èµå¼æ¶æº¢åºæ以æ好ç¨å¯¹åºå®¹å¨çsize_type
ä½ ç¨intæ¶ä¸è¬ç¼è¯å¨é½æè¦åï¼ç±»ä¼¼âä»æ 符å·å°æ符å·è½¬æ¢å¯è½ä¸¢å¤±æ°æ®âä¹ç±»ç
全排列VB源代码
文章标题:全排列VB源代码与C++实现,附非递归算法解答在编程世界中,全排列算法是一个常被提及的主题,尤其在解决组合数学问题时。本文将展示如何使用 Visual Basic (VB) 和 C++ 语言实现全排列,并提供一个非递归算法的解答,帮助读者理解和解决相关问题。
首先,让我们聚焦于 VB 语言的实现。在 VB 中,我们可以通过编写一段代码来生成给定字符串的所有全排列。下面是一个典型的 VB 代码示例:
vb
Option Explicit
Private Sub Command1_Click()
Dim nt As Double: nt = Timer
List1.Visible = False: List1.Clear
Permutation("", Text1.Text)
List1.Visible = True
Debug.Print Timer - nt,
End Sub
Private Sub Permutation(pre As String, s As String)
Dim i As Long
If Len(s) = 1 Then List1.AddItem pre & s: Exit Sub
For i = 1 To Len(s)
Permutation(pre & Mid$(s, i, 1), Left$(s, i - 1) & Mid$(s, i + 1))
Next
End Sub
这段代码实现了一个递归过程来生成全排列。它首先检查字符串的长度,如果长度为1,则直接将字符串与前面的元素合并并添加到列表中。如果字符串长度大于1,则进行循环以取出待排列串的任意一位,并将该字符插入到已取出的字符串后,然后递归调用自身,同时更新待排列的字符串。这一过程一直持续到所有字符排列完成。
接下来,我们转向 C++ 实现,一种更广泛使用的编程语言。C++ 中的全排列实现通常使用模板类,以适应不同类型的元素。下面是一个简单的 C++ 全排列实现:
cpp
template class Type>
void Perm(Type list[], int k, int m) {
if (k == m) {
for (int i = 0; i <= m; i++) {
cout << list[i];
}
cout << endl;
} else {
for (int i = k; i <= m; i++) {
Swap(list[k], list[i]);
Perm(list, k + 1, m);
Swap(list[k], list[i]);
}
}
}
此模板函数 `Perm` 接受一个类型为 `Type` 的数组、起始索引 `k` 和结束索引 `m`,并递归地生成从 `k` 到 `m` 的数组的所有全排列。通过交换数组中的元素,我们逐步构建全排列并打印结果。
对于一个非递归的全排列算法,我们可以通过一个循环和条件判断来实现。下面是一个用 C++ 实现的非递归算法:
cpp
#include
int *n;
void arge(int *x, int size) {
int *t = new int[size];
int totoal = 0;
int pos = size - 2;
int just = 0;
for (int i = 0; i < size; i++) {
t[0] = 1;
}
while (1) {
for (int i = 0; i < size; i++) {
printf("%d ", x[i]);
}
printf("\n");
totoal++;
pos = size - 2;
while (x[pos] > x[pos + 1]) {
pos--;
t[x[pos + 1] - 1] = 0;
}
if (pos < 0) {
break;
}
t[x[pos] - 1] = 0;
t[x[pos + 1] - 1] = 0;
for (int i = pos + 1; i < size; i++) {
for (int j = 1; j <= size; j++) {
if (t[j - 1] == 0) {
x[i] = j;
t[j - 1] = 1;
break;
}
}
}
}
printf("totoal = %d\n", totoal);
delete[] t;
}
这个非递归算法通过使用一个辅助数组 `t` 来跟踪已排序的元素,从而避免了递归调用。通过循环和条件判断,该算法实现了从数组中生成全排列,并打印每个排列的结果。
通过以上三种不同的实现方式,我们可以看到全排列问题在不同编程语言中的解法,每种方法都有其优势和应用场景。理解这些不同的解决方案有助于提升编程技能,解决更多复杂问题。
扩展资料
从n个不同元素中任取m(m≤n)个元素,按照一定的顺序排列起来,叫做从n个不同元素中取出m个元素的一个排列。当m=n时所有的排列情况叫全排列。