1 条题解

  • 0
    @ 2024-5-10 0:45:58

    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;
    }
    

    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;
    }
    

    Pascal :

    program hehe;
    var a:string;i,s,x,code:integer;
    begin
    readln(a);s:=0;
    while a<>'#' do
     begin
     for i:=1 to length(a)-1 do
      begin
      val(a[i],x,code);
      s:=s+x;
      end;
     if a[length(a)]='e' then if odd(s) then begin delete(a,length(a),1);insert('1',a,length(a)+1);end
                              else begin delete(a,length(a),1);insert('0',a,length(a)+1);end;
     if a[length(a)]='o' then if odd(s) then begin delete(a,length(a),1);insert('0',a,length(a)+1);end
                              else begin delete(a,length(a),1);insert('1',a,length(a)+1);end;
     writeln(a);
     readln(a);s:=0;
     end;
    end.
    
    

    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'));
    		}
    	}
    
    }
    
    

    Python :

    import sys
      
    for line in sys.stdin:
        data = list(line.split()[0])   
        if data[0]!='#':
            c1 = data.count('1')
            if c1%2==0:
               if data[-1]=='e':
                  data[-1]='0'
                  print ''.join([i for i in data])
               elif data[-1]=='o':
                  data[-1]='1'
                  print ''.join([i for i in data])
            else:
               if data[-1]=='e':
                  data[-1]='1'
                  print ''.join([i for i in data])
               elif data[-1]=='o':
                  data[-1]='0'
                  print ''.join([i for i in data])      
    

    C# :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string str;
                while ((str=Console.ReadLine())!=null && str!="#")
                {
                    int flag = str.Split('1').Length - 1;
                    string ans=string.Empty;
                    if (str[str.Length - 1] == 'e')
                    {
                        if (flag % 2 == 0)
                            ans = "0";
                        else ans = "1";
                    }
                    else
                    {
                        if (flag % 2 == 0)
                            ans = "1";
                        else ans = "0";
                    }
                    
                    Console.WriteLine(str.Substring(0,str.Length-1)+ans);
                }
            }
        }
    }
    
    
    
    
    
    
    • 1

    信息

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