Set d = CreateObject("scripting.dictionary")
Set dd = CreateObject("scripting.dictionary")
Set s1 = Sheets("SHEET1")
Set s2 = Sheets("SHEET2")
For i = 2 To s1.[a65536].End(3).Row
aa = s1.Cells(i, 1) & "|" & s1.Cells(i, 2) & "|" & s1.Cells(i, 3)
d(aa) = ""
Next
For j = 2 To s2.[a65536].End(3).Row
bb = s2.Cells(j, 1) & "|" & s2.Cells(j, 2) & "|" & s2.Cells(j, 3)
dd(bb) = ""
If d.exists(bb) Then
d.Remove (bb)
Else
s2.Cells(j, 4) = "遗漏"
End If
Next
For i = 2 To s1.[a65536].End(3).Row
cc = s1.Cells(i, 1) & "|" & s1.Cells(i, 2) & "|" & s1.Cells(i, 3)
If dd.exists(cc) Then
dd.Remove (cc)
Else
s1.Cells(i, 4) = "多出"
End If
Next
End Sub
头文件:(另存为SeqStack.h)typedef struct
{
DataType stack[MaxStackSize]
int top
} SeqStack
void StackInitiate(SeqStack *S)/*初始化顺序堆栈S*/
{
S->top = 0 /*定义初始栈顶下标值*/
}
int StackNotEmpty(SeqStack S)
/*判顺序堆栈S非空否,非空则返回1,否则返回0*/
{
if(S.top <= 0) return 0
else return 1
}
int StackPush(SeqStack *S, DataType x)
/*把数据元素值x压入顺序堆栈S,入栈成功则返回1,否则返回0 */
{
if(S->top >= MaxStackSize)
{
printf("堆栈已满无法插入! \n")
return 0
}
else
{
S->stack[S->top] = x
S->top ++
return 1
}
}
int StackPop(SeqStack *S, DataType *d)
/*d出顺序堆栈S的栈顶数据元素值到参数d ,出栈成功则返回1,否则返回0*/
{
if(S->top <= 0)
{
printf("堆栈已空无数据元素出栈! \n")
return 0
}
else
{
S->top --
*d = S->stack[S->top]
return 1
}
}
int StackTop(SeqStack S, DataType *d)
/*取顺序堆栈S的当前栈顶数据元素值到参数d ,成功则返回1,否则返回0*/
{
if(S.top <= 0)
{
printf("堆栈已空! \n")
return 0
}
else
{
*d = S.stack[S.top - 1]
return 1
}
}
括号问题
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define MaxStackSize 100
typedef char DataType
#include "SeqStack.h"
void ExpIsCorrect(char exp[], int n)
//判断有n个字符的字符串exp左右括号是否配对正确
{
SeqStack myStack//定义链式堆栈
int i
char c
StackInitiate(&myStack)
for(i = 0i <ni++)
{
if((exp[i] == '(') || (exp[i] == '[') || (exp[i] == '{'))
StackPush(&myStack, exp[i]) //入栈
else if(exp[i] == ')' &&StackNotEmpty(myStack)
&&StackTop(myStack, &c) &&c == '(')
StackPop(&myStack, &c)//出栈
else if(exp[i] == ')' &&StackNotEmpty(myStack)
&&StackTop(myStack, &c) &&c != '(')
{
printf("左右括号配对次序不正确!\n")
return
}
else if(exp[i] == ']' &&StackNotEmpty(myStack)
&&StackTop(myStack, &c) &&c == '[')
StackPop(&myStack, &c)//出栈
else if(exp[i] == ']' &&StackNotEmpty(myStack)
&&StackTop(myStack, &c) &&c != '[')
{
printf("左右括号配对次序不正确!\n")
return
}
else if(exp[i] == '}' &&StackNotEmpty(myStack)
&&StackTop(myStack, &c) &&c == '{')
StackPop(&myStack, &c)//出栈
else if(exp[i] == '}' &&StackNotEmpty(myStack)
&&StackTop(myStack, &c) &&c != '{')
{
printf("左右括号配对次序不正确!\n")
return
}
else if(((exp[i] == ')') || (exp[i] == ']') || (exp[i] == '}'))
&&!StackNotEmpty(myStack))
{
printf("右括号多于左括号!\n")
return
}
}
if(StackNotEmpty(myStack))
printf("左括号多于右括号!\n")
else
printf("左右括号匹配正确!\n")
}
void main(void)
{
char a[] = "(())abc{[)(]}" //测试例子1。左右括号配对次序不正确
char b[] = "(()))abc{[]}" //测试例子2。右括号多于左括号
char c[] = "(()()abc{[]}" //测试例子3。左括号多于右括号
char d[] = "(())abc{[]}" //测试例子4。左右括号匹配正确
int n1 = strlen(a)
int n2 = strlen(b)
int n3 = strlen(c)
int n4 = strlen(d)
ExpIsCorrect(a, n1)
ExpIsCorrect(b, n2)
ExpIsCorrect(c, n3)
ExpIsCorrect(d, n4)
}
二者放于同一目录下即可
Do While Not EOF(1) ' 循环至文件尾。Line Input #1, a ' 读入一行数据并将其赋予某变量。
a= Replace(a, "AA", "11")
a= Replace(a, "BB", "11")
b= b &Replace(a, "CC", "11") &vbCrLf ' 替换并放入变量
Loop
多做两次替换就行了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)