3 solutions

  • 0
    @ 2026-4-15 19:39:53
    #include<bits/stdc++.h>
    using namespace std;
    struct s{
    	string name;
    	int yu,shu,yin,zong;
    };
    
    s g[100010];
    int main()
    {
    	int n;
    	cin>>n;
    	for(int i=0;i<n;i++){
    		cin>>g[i].name>>g[i].yu>>g[i].shu>>g[i].yin;
    		g[i].zong=g[i].yu+g[i].shu+g[i].yin;
    	}
    
    	for(int i=0;i<n;i++){
    		for(int j=i+1;j<n;j++){
    			if(g[i].shu-g[j].shu>=-5&&g[i].shu-g[j].shu<=5){
    				if(g[i].yu-g[j].yu>=-5&&g[i].yu-g[j].yu<=5){
    					if(g[i].yin-g[j].yin>=-5&&g[i].yin-g[j].yin<=5){
    						if(g[i].zong-g[j].zong>=-10&&g[i].zong-g[j].zong<=10){
    							cout<<g[i].name<<" "<<g[j].name<<endl;
    						}
    					}
    				}
    			}
    		}
    	}
    	return 0;
    }
    
    • -1
      @ 2026-2-25 11:05:41

      #include<bits/stdc++.h> using namespace std; struct s{ string name; int yu,shu,yin,zong; }; bool cmp(s a,s b) { if(a.name<b.name) return 1; return 0; } s g[9876]; int main() { int n; cin>>n; for(int i=0;i<n;i++){ cin>>g[i].name>>g[i].yu>>g[i].shu>>g[i].yin; g[i].zong=g[i].yu+g[i].shu+g[i].yin; } sort(g,g+n,cmp); for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ if(g[i].shu-g[j].shu>=-5&&g[i].shu-g[j].shu<=5){ if(g[i].yu-g[j].yu>=-5&&g[i].yu-g[j].yu<=5){ if(g[i].yin-g[j].yin>=-5&&g[i].yin-g[j].yin<=5){ if(g[i].zong-g[j].zong>=-10&&g[i].zong-g[j].zong<=10){ cout<<g[i].name<<" "<<g[j].name<<endl; } } } } } } return 0; }

      • -1
        @ 2026-2-25 10:49:12

        #include #include #include using namespace std; struct stu { string name; int chinese, math, english, total; } a[1001]; bool qwq(stu a, stu b) { if ( abs(a.chinese - b.chinese) <= 5 && abs(a.math - b.math) <= 5 && abs(a.english - b.english) <= 5 && abs(a.total - b.total) <= 10 ) return 1; else return 0; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i].name >> a[i].chinese >> a[i].math >> a[i].english; a[i].total = a[i].chinese + a[i].math + a[i].english; } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (qwq(a[i], a[j])) cout << a[i].name << " " << a[j].name << endl; } } return 0; }

        • 1

        Information

        ID
        1615
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        1
        Tags
        (None)
        # Submissions
        11
        Accepted
        5
        Uploaded By