1 条题解

  • 0
    @ 2021-6-15 1:39:22

    C :

    #include<stdio.h>
    #include<string.h>
    #define N 110
    int main()
    {
        char a[N];
        int i,n,aa[2],m,p1,p2,j,p3;
        scanf("%d %d %d",&p1,&p2,&p3);
        scanf("%s",a);
        for(i=0;a[i]!='\0';){
            if(a[i]=='-'){
                n=i;
                if(a[n-1]>='a' && a[n+1]<='z'){
                    aa[0]=a[n-1]-'a';
                    aa[1]=a[n+1]-'a';
                    if(aa[0]>=aa[1]) printf("-");
                    else if(aa[0]==aa[1]-1) printf("");
                    else{
                        //printf("%c",aa[0]+'a');
                        if(p3==1){
                            for(m=aa[0]+1;m<aa[1];m++){
                                if(p1==1)
                                    for(j=1;j<=p2;j++) printf("%c",m+'a');//小写字母;
                                else if(p1==2)
                                    for(j=1;j<=p2;j++) printf("%c",m+'A');
                                else
                                    for(j=1;j<=p2;j++) printf("*");
                            }
                        }
                        else{
                            for(m=aa[1]-1;m>=aa[0]+1;m--){
                                if(p1==1)
                                    for(j=1;j<=p2;j++) printf("%c",m+'a');//小写字母;
                                else if(p1==2)
                                    for(j=1;j<=p2;j++) printf("%c",m+'A');
                                else
                                    for(j=1;j<=p2;j++) printf("*");
                            }
                        }
                        //printf("%c",aa[1]+'a');
                    }
                }
                else if(a[n-1]>='0' && a[n+1]<='9'){
                    aa[0]=a[n-1]-'0';
                    aa[1]=a[n+1]-'0';
                    if(aa[0]>=aa[1]) printf("-");
                    else if(aa[0]==aa[1]-1) printf("");
                    else{
                        //printf("%c",aa[0]+'a');
                        if(p3==1){
                            for(m=aa[0]+1;m<aa[1];m++){
                                if(p1==1 || p1==2)
                                    for(j=1;j<=p2;j++) printf("%c",m+'0');
                                else
                                    for(j=1;j<=p2;j++) printf("*");
                            }
                        }
                        else{
                            for(m=aa[1]-1;m>=aa[0]+1;m--){
                                if(p1==1 || p1==2)
                                    for(j=1;j<=p2;j++) printf("%c",m+'0');
                                else
                                    for(j=1;j<=p2;j++) printf("*");
                            }
                        }
                        //printf("%c",aa[1]+'a');
                    }
                }
                else{
                    printf("%c",a[i]);
                }
                i++;
            }
            else{
                printf("%c",a[i]);
                i++;
            }
        }
        return 0;
    }
    
    

    C++ :

    //先存再输出是很愚蠢的方法!!
    //一边改一边输出!! 
    #include <iostream> 
    #include <cstdio>
    #include <cstring>
    using namespace std;
    int p1,p2,p3;
    int flag;
    char t,i,flag2;
    	
    char change(char c){					//p1=2填充大写字母 
    	return c-32;
    }
    
    void ptkz(char p){
    	int i;
    	if (p1==1){
    		for(i=1;i<=p2;i++){
    			cout<<p;				//直接输出小写字母 
    		}
    	}
    	if (p1==2&&p>='a'&&p<='z'){
    		for(i=1;i<=p2;i++){
    			cout<<change(p);		//输出大写字母 
    		}
    	}
    	if(p1==2&&p>='0'&&p<='9'){
    		for(i=1;i<=p2;i++){
    			cout<<p;				//填充数字串 
    		}
    	}
    }
    void kzxh(){
    	int i;
    	for(i=1;i<=p2;i++){
    		cout<<"*";					//填充星号串 
    	}
    }
    
    int judge(char a,char b){
    	if(a>='a'&&a<='z'&&b>='a'&&b<='z')
    	if(a<b) return 1;
    	if(a>='0'&&a<='9'&&b>='0'&&b<='9')
    	if(a<b) return 1;
    	return 0;
    }
    
    int main(){
    	cin>>p1>>p2>>p3;
    	flag2='#';		//作为一个标志使用 
    	while(cin>>t){
    		if(t!='-')cout<<t;		//非 '-' 则直接输出即可 
    		else{
    			if(cin>>t){
    				flag=judge(flag2,t);
    				if(flag){
    					if(p3==1){
    						for(i=flag2+1;i<=t-1;i++){
    							if(p1!=3)ptkz(i);else kzxh();
    						}
    					}
    					else{
    						for(i=t-1;i>=flag2+1;i--){
    							if(p1!=3)ptkz(i);else kzxh();
    						}
    					}
    					cout<<t;
    				}
    				else cout<<"-"<<t;
    			}
    			else cout<<"-";
    		}
    		flag2=t;
    	}
    	cout<<endl;
    	return 0;
    }
    

    Pascal :

    var
      p1,p2,p3,i:longint;
      from,en,ch:char;
      ans:ansistring;
      s:string;
    
    function operate(ch:char):string;
      var rt:string;
        i:longint;
      begin
        if (ch in ['a'..'z'])and(p1=2)
          then ch:=chr(ord(ch)-32);
        if p1=3 then ch:='*';
        rt:='';
        for i:=1 to p2 do rt:=rt+ch;
        exit(rt);
      end;
    
    begin
      readln(p1,p2,p3);
      readln(s);
      ans:=''; i:=1;
      while i<=length(s) do
        begin if s[i]='-' then
          begin if (i>1)and(i<length(s))and(((s[i-1] in['0'..'9'])and(s[i+1] in ['0'..'9'])and(s[i-1]<s[i+1]))
                   or ((s[i-1] in ['a'..'z'])and(s[i+1] in ['a'..'z'])and(s[i-1]<s[i+1])))
                  then begin
                         from:=chr(ord(s[i-1])+1);
                         en:=chr(ord(s[i+1])-1);
                         if p3=1
                      then for ch:=from to en do
                             ans:=ans+operate(ch)
                      else for ch:=en downto from do
                             ans:=ans+operate(ch);
                       end
                  else ans:=ans+'-';
           end
           else ans:=ans+s[i];
        inc(i);
      end;
      writeln(ans);
    end.
    
    
    • 1

    信息

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