1 条题解

  • 0
    @ 2025-11-30 16:26:39

    C :

    //编写一个译码程序,把一个英语句子(包含大小写英文字母)译成数字代码。译码规则是以数字1代替字母a,数字2代替字母b,……,
    //26代替字母z;大写字母也按相同规则处理,即用1~26代替A~Z,如遇空格则打印一个星号‘*’,英文句子以‘.‘结束。
    #include<stdio.h>
    #include<string.h>
    char m[100]="qwertyuioplkjhgfdsazxcvbnm";char mm[100]="QWERTYUIOPLKJHGFDSAZXCVBNM";
    int main()
    {char a[8000];int i;
    gets(a);
    	for(i=0;i<strlen(a);i++)
    	{if(strchr(m,a[i])!=NULL)printf("%d",a[i]-'a'+1);
    	else if(strchr(mm,a[i])!=NULL)printf("%d",a[i]-'A'+1);
    	else if(a[i]==' ')printf("*");if(a[i]=='.')return 0;}
    	
    	
    	return 0;
    }
    

    C++ :

    //character
    #include<cstdio>
    using namespace std;
    int main()
    {
    	char x;
    	while(scanf("%c",&x)==1)
    	{
    		if(x=='.') break;
    		if(x==' ') printf("*");
    		if(x>='a' && x<='z') printf("%d",x-'a'+1);
    		if(x>='A' && x<='Z') printf("%d",x-'A'+1); 
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    1208
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者