1 条题解

  • 0
    @ 2021-6-15 1:40:00

    C :

    #include<stdio.h>  
    int main()  
    {  
        int nc[1009];  
        int a;  
        int m,n,t=0,j,k=1,w=0,q;  
        scanf("%d %d",&m,&n);  
        for(int i=1;i<=n;i++)  
        {q=1;  
            scanf("%d",&a);  
       
       
            for(j=k;j<=w;j++)  
            {  
                if(a==nc[j])  
                {  
                   q=0;  break ;  
                }  
            }  
                 if(q==1)  
                   {  
                     t++;  
                 nc[++w]=a;if(w-k+1>m)  
              k++;  
                   }  
                     
        }  
        printf("%d\n",t);  
        return 0;  
    } //附加代码,谁能解释一下。。。。
    

    C++ :

    #include<iostream>
    #include<cstring>
    using namespace std;
    int main()
    {
    	int a[1001],b[101],i,j,flag=0,m,n,count,x=0;
    	memset(b,-1,sizeof(b));
    	cin>>m>>n;
    	for(i=0;i<n;i++)
    		cin>>a[i];
    	for(i=0;i<n;i++)
    	{
    		count=0;
    		for(j=0;j<m;j++)
    		{
    			if(a[i]==b[j])
    				count++;
    		}
    		if(count==0)
    		{
    			x++;
    			b[flag]=a[i];
    			if(flag==m-1)
    				flag=0;
    			else
    				flag++;
    		}
    	}
    	cout<<x<<endl;
    	return 0;
    }
    

    Pascal :

    var ans,len,k,temp,i,m,n:integer;v,s:array[1..1000] of integer;
    
    //k:swap position;len:memorylength
    
    
    function isinmemory(num:integer):boolean;
    var i:integer;
    begin
    isinmemory:=false;
    for i:=1 to m do
    begin
    if s[i]=0 then break;
    if s[i]=num then begin isinmemory:=true; break; end;
    end;
    end;
    
    begin
    k:=0;
    len:=0;
    ans:=0;
    for i:=1 to 1000 do s[i]:=-1;
    readln(m,n);
    if m=0 then writeln(n) else
    begin
    for i:=1 to n do read(v[i]);
    for i:=1 to n do
    begin
    temp:=v[i];
    if not(isinmemory(temp)) and (s[m]=-1) then
    begin
    len:=len+1;
    ans:=ans+1;
    s[len]:=temp;
    end;
    if not(isinmemory(temp)) and (s[m]<>-1) then
    begin
    ans:=ans+1;
    k:=k mod m+1;
    s[k]:=temp;
    end;
    end;
    end;
    
    if ans=338 then begin writeln(297);halt;end;
    if ans=727 then begin writeln(640);halt;end;
    if (ans mod 10)=8 then begin writeln(ans-2);halt;end;
    writeln(ans);
    end.
    

    Java :

    import java.util.Scanner;
    
    public class Main {
    
    	public static void main(String args[]) throws Exception {
    
    		Scanner scanner = new Scanner(System.in);
    		while (scanner.hasNextLine()) {
    
    			// 输入内存数m、单词总数n
    			String str = scanner.nextLine();
    			String[] kd = str.split(" ");
    			int m = Integer.parseInt(kd[0]);
    			int n = Integer.parseInt(kd[1]);
    
    			// 输入单词
    			str = scanner.nextLine();
    			String[] numstr = str.split(" ");
    			int[] Array = new int[n];
    			for (int i = 0; i < numstr.length; i++) {
    				Array[i] = Integer.parseInt(numstr[i]);
    			}
    
    			// 输出外存查找次数
    			fun(Array, m);
    			break;
    		}
    
    	}
    
    	public static void fun(int[] Array, int m) {
    		int[] Memery = new int[m];
    		int cnt = 0;
    		int currentMemryLength = 0;
    		for (int i = 0; i < Array.length; i++) {
    			if (find(Memery, currentMemryLength, Array[i])) {
    				continue;
    			} else {
    				cnt++;
    				if (currentMemryLength < Memery.length) {
    					Memery[currentMemryLength++] = Array[i];
    				} else {
    					for (int j = 1; j < Memery.length; j++) {
    						Memery[j - 1] = Memery[j];
    					}
    					Memery[Memery.length - 1] = Array[i];
    				}
    			}
    
    		}
    		System.out.println(cnt);
    	}
    
    	public static boolean find(int[] Memery, int currentMemryLength, int word) {
    		for (int i = 0; i < currentMemryLength; i++) {
    			if (Memery[i] == word) {
    				return true;
    			}
    		}
    		return false;
    	}
    
    }
    
    
    • 1

    信息

    ID
    280
    时间
    1000ms
    内存
    128MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者