1 条题解

  • 0
    @ 2024-12-24 9:59:26

    C :

    #include<stdio.h>
    #include<string.h>
    
    int main()
    {
    	int i,k,l;
    	char a[35];
    	while(gets(a))
    	{
    		k=0;
    		if(!strcmp(a,"#"))
    			break;
    		l=strlen(a);
    		for(i=0;i<l;i++)
    			if(a[i]=='1')
    				k++;
    		if(k%2==0)
    		{
    			if(a[l-1]=='e')
    				a[l-1]='0';
    			else
    				a[l-1]='1';
    		}
    		else
    		{
    			if(a[l-1]=='e')
    				a[l-1]='1';
    			else
    				a[l-1]='0';
    		}
    		printf("%s\n",a);
    	}
    	return 0;
    }
    

    Java :

    import java.util.Scanner;
    
    public class Main {
    
    	public static void main(String[] args) {
    		Scanner in = new Scanner(System.in);
    		while(true){
    			String s = in.nextLine();
    			if(s.equals("#"))break;
    			char[] mai = s.substring(0, s.length()-1).toCharArray();
    			char com = s.charAt(s.length()-1);
    			int cou = 0;
    			for(char c:mai)
    				if(c=='1')cou++;
    			if(cou%2==0&&com=='e' || cou%2==1&&com=='o')System.out.println(s.replace(com, '0'));
    			else System.out.println(s.replace(com, '1'));
    		}
    	}
    
    }
    
    
    • 1

    信息

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