1 条题解

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

    C :

    #include<stdio.h>
    #include<string.h>
    
    int main()
    {
    	int t,i,n;
    	char a[100];
    	scanf("%d",&t);
    	while(t--)
    	{
    		memset(a,'0',sizeof(a));
    		scanf("%s%d",a,&n);
    		for(i=0,a[strlen(a)]='0';;i++)
    			if(a[i]=='.')
    				break;
    		printf("%c\n",a[i+n]);
    	}
    	return 0;
    }
    

    C++ :

    #include<stdio.h>
    #include<string.h>
    
    int main()
    {
    	int t,i,n;
    	char a[100];
    	scanf("%d",&t);
    	while(t--)
    	{
    		memset(a,'0',sizeof(a));
    		scanf("%s%d",a,&n);
    		for(i=0,a[strlen(a)]='0';;i++)
    			if(a[i]=='.')
    				break;
    		printf("%c\n",a[i+n]);
    	}
    	return 0;
    }
    

    Pascal :

    var
     o,i,t,n:longint;
     s:string;
    begin
     readln(n);
     for o:=1 to n do begin 
         readln(s);
    	 i:=pos(' ',s);
    	 val(copy(s,i+1,length(s)-i),t);
    	 if (t>i-pos('.',s)-1)  then writeln('0') else writeln(copy(s,pos('.',s)+t,1));
     end;
    end.
    

    Java :

    import java.util.Scanner;
    
    public class Main {
    
    	public static void main(String[] args) {
    		Scanner in = new Scanner(System.in);
    		int t = Integer.parseInt(in.nextLine());
    		while(t-->0){
    			String s = in.nextLine();
    			String[] ss = s.split(" ");
    			int cou = Integer.parseInt(ss[1]);
    			String[] ss1 = ss[0].split("\\.");
    			try{
    				System.out.println(ss1[1].charAt(cou-1));
    			}catch( java.lang.StringIndexOutOfBoundsException e){
    				System.out.println(0);
    			}
    		}
    	}
    
    }
    
    

    Python :

    times = int(raw_input())
    while times > 0:
    	times -= 1
    	number = raw_input()
    	if int(number[-1]) > (number.index(' ') - number.index('.') - 1):
    		print 0
    	else:
    		print number[number.index('.') + int(number[-1])]
    
    
    • 1

    信息

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