注册 登录
编程论坛 VB6论坛

求高手用VB编程

Wimong 发布于 2013-05-17 23:45, 1127 次点击
1-9代表A-I;字母A-Z代表j直到z,a,直到i
10 回复
#2
Wimong2013-05-17 23:53
帮帮忙吧。。。。。。
#3
wxflw2013-05-18 00:58
没看懂
#4
Wimong2013-05-18 01:50
#include<stdio.h>
#include<conio.h>
void main()
{
  char str[30];
    char c[30];
    int i;
 scanf("%s",str);
    for(i=1;i<=30;i++)
        while(str[i]>=1||str[i]<=9)
             {c[i]=str[i]+16;}
         while(str[i]>='A'||str[i]<='Q')
            {c[i]=str[i]+41;}
         while(str[i]>='R'||str[i]<='Z')
            {c[i]=str[i]+15;}
        while(str[i]==0)
            {printf(" ");}
   printf("%C",c[i]);
}
#5
Wimong2013-05-18 01:55
就是英国间谍007受到一个字条,:“4F0EFK0KILJK08RIP”,已知道
(1)数字1--9代表字母A--I
(2)字母A--Q(就是ABCDEFGHIJKLMNOPQ,以下同理)代表j--z
       剩下的 R--Z代表a--i
这个无结果啊??
#include<stdio.h>
#include<conio.h>
void main()
{
  char str[30];
    char c[30];
    int i;
scanf("%s",str);
    for(i=1;i<=30;i++)
        while(str[i]>=1||str[i]<=9)
             {c[i]=str[i]+16;}
         while(str[i]>='A'||str[i]<='Q')
            {c[i]=str[i]+41;}
         while(str[i]>='R'||str[i]<='Z')
            {c[i]=str[i]+15;}
        while(str[i]==0)
            {printf(" ");}
   printf("%C",c[i]);
}
#6
Wimong2013-05-18 01:59
谢谢wxflw,这么晚了还回复我。有空请你去喝茶。
#7
lowxiong2013-05-18 03:31
对c不熟(用VB写就太简单了),不过在for循环内对单个数组的判断应该用if吧,while是条件循环的,再就是逻辑运算是与(&&)我觉得应该这样写(已通过VC6编译运行):
#include<stdio.h>
#include<conio.h>
void main()
{
  char str[30];
  char c[30];
  int i;
  scanf("%s",str);
  for(i=0;i<=30;i++)
  {
     if (str[i]>48&&str[i]<58)
       {c[i]=str[i]+16;}      //1-9的处理
     if (str[i]>64&&str[i]<82)
       {c[i]=str[i]+41;}      //A-Q的处理
     if (str[i]>81&&str[i]<91)
       {c[i]=str[i]+15;}      //R-Z的处理
     if(str[i]==0){c[i]=0;}
  }
  printf("%s",c);
}
   

[ 本帖最后由 lowxiong 于 2013-5-18 04:21 编辑 ]
#8
Wimong2013-05-18 03:53
已经基本解决,不过数字0要变为空格,做不成,最终答案是:Do nor trust Hary
#include<stdio.h>

void main()
{
  char str[30];
  char c[30];
    int i=0;
 scanf("%s",str);
 for(i=0;i<=30;i++)
       {  
         if(str[i]>=1||str[i]<=9)
             {c[i]=str[i]+16;}
          if(str[i]>='A'&&str[i]<='Q')
            {c[i]=str[i]+41;}
          if(str[i]>='R'&&str[i]<='Z')
            {c[i]=str[i]+15;}
        if (str[i]==0)
            {printf("--");}}
for (i=0;i<=30;i++)        
   printf("%c",c[i]);
}
#9
lowxiong2013-05-18 04:22
晚上好,很勤奋嘛!你用||应该得不到正确答案的,应该用&&,逻辑与,我刚刚调试通过了的。以下是我在向导生成的console application模式下的hello world的基础上修改后调试通过的,正确结果是Do not trust Hary。
// aaa.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<stdio.h>
#include<conio.h>

int main(int argc, char* argv[])
{
  char str[30];
  char c[30];
  int i;
  scanf("%s",str);
  for(i=0;i<=30;i++)
  {
     if (str[i]>48&&str[i]<58)
       {c[i]=str[i]+16;}      //1-9的处理
     if (str[i]>64&&str[i]<82)
       {c[i]=str[i]+41;}      //A-Q的处理
     if (str[i]>81&&str[i]<91)
       {c[i]=str[i]+15;}      //R-Z的处理
     if(str[i]==0){c[i]=0;}   //结束符处理
     if(str[i]==48){c[i]=32;}  //字符0的处理
  }
  printf("%s",c);
  scanf("%s",str);
  return 0;
}



[ 本帖最后由 lowxiong 于 2013-5-18 04:37 编辑 ]
#10
Wimong2013-05-18 15:00
谢谢lowxiong。 一定要输入的数字与1(1对应ASCII码为49)相比较,

            
#11
风吹过b2013-05-18 20:54
VB 的还是 C 的啊。

程序代码:

Dim s As String
Dim i As Long
Dim s2() As Byte

s = InputBox("请输入密文:", "密文")
s2 = StrConv(s, vbFromUnicode)          '转BYTE数组
For i = 0 To UBound(s2)            '处理过程抄 lowxiong 的 C 代码
    Select Case s2(i)
        Case 48
            s2(i) = 32
        Case 49 To 57
            s2(i) = s2(i) + 16
        Case 65 To 81
            s2(i) = s2(i) + 41
        Case 82 To 90
            s2(i) = s2(i) + 15
        End Select
Next i
MsgBox StrConv(s2, vbUnicode)

1