2 solutions

  • 0
    @ 2021-12-13 21:17:02

    蒟蒻的代码,若有不对欢迎指正

    #include<bits/stdc++.h>
    using namespace std;
    char a[101];
    char b[101];
    int c[10000]; 
    int main(){
    	int n,m;
    	cin>>n>>m;
    	int k=0;
    	for(int i=0;i<n;i++){
    		cin>>a[i];
    	}
    	for(int j=0;j<m;j++){
    		cin>>b[j];
    	}
    	for(int i=0;i<n;i++){
    		for(int j=0;j<m;j++){
    			c[k]=abs((int)a[i]-(int)b[j]);
    			if(k>0){
    				if(c[k]>c[k-1]){
    					c[k]=c[k-1];
    				}
    			} 
    			k++;
    		}
    	}
    	if(c[k-1]==0 || c[k-1]==1){
    		printf("NO");	
    	}
    	else{
    		int flag=0;
    		for(int i=2;i<k;i++){
    			if(k%i==0){
    				flag=1;
    				break;
    			}
    		}
    		if(flag==0){
    			printf("YES");
    		}
    		else printf("NO");	
    	}
    	return 0;
    }
    
    • 0
      @ 2021-12-4 11:44:26

      这道题没什么讲的,细心一点就可以了 (QAQ)

      #include<cstdio>
      #include<cmath>
      using namespace std;
      int IsPrime(int n){
      	int i;
      	if(n%2==0||n==1) return 0;
      	for(i = 3;i <= sqrt(n);i+=2) if(n%i==0) return 0;
      	return 1; 
      }
      int main()
      {
          int x[1001],y[1001],c;
          int i,j,m,n,min=0x3f3f3f3f;
          scanf("%d %d",&m,&n);
          for(i=0; i<m; i++)
          {
              scanf("%1d",&x[i]);
          }
          for(i=0; i<n; i++)
          {
              scanf("%1d",&y[i]);
          }
          for(i=0; i<m; i++)
          {
              for(j=0; j<n; j++)
              {
                  c=abs(x[i]-y[j]);
                  if(c<min)
                      min=c;
              }
          }
          if(IsPrime(min))
          printf("YES\n");
          else
          printf("NO\n");
          return 0;
      }
      
      • 1

      Information

      ID
      192
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      7
      Tags
      # Submissions
      122
      Accepted
      24
      Uploaded By