12 条题解

  • 3
    @ 2023-9-2 15:24:57
    #include<bits/stdc++.h>
    using namespace std;
    struct unhappy{
        int school,other,day;
    };
    bool cmp(unhappy a, unhappy b){
        if(a.school+a.other==b.school+b.other){
            return a.day<b.day;
        }else{
            return a.school+a.other>b.school+b.other;
        }
    }
    unhappy a[8];
    int main(){
        for(int i=1;i<=7;i++){
            cin>>a[i].school>>a[i].other;
            a[i].day=i;
        }sort(a+1,a+8,cmp);
        if(a[1].school+a[1].other<8)
            cout<<0;
        else
            cout<<a[1].day;
        return 0;
    }
    
    • 2
      @ 2022-8-28 18:41:09
      #include<iostream>
      #include<cstdio>
      #include<cstdlib>
      using namespace std;    
      int main ()
      {
          int a,b,s,max=0,i,day=0;  //a,b是我们津津(以下简称JJ)每天上课时间,s意为sum是上课时间之和 
          for (i=1;i<8;i++)   // i为循环变量,day是JJ一周最不高兴的一天 
            {
              cin>>a>>b;    //输入a,b 
              s=a+b;   //计算一天的上课时间 
              if ((s>max)&&(s>8)) max=s,day=i;  //在超过8小时且比之前几天都大的s时,将s赋给最大值,并记录下JJ的这天 
            }
          cout<<day; //由于day初值是0,所以如果JJ一周都开心就输出0 
          return 0;             
      }
      
      • @ 2022-9-3 14:59:01

        请不要直接发送AC代码,如果发现就会直接删除的哦~ 请遵守良好的学习环境。

    • 1
      @ 2024-5-2 17:45:51
      #include <bits/stdc++.h> 
      using namespace std;
      #define ll long long
      #define s string
      #define co cout
      #define ci cin
      #define re return
      ll a[10],b[10],ans=0;
      int main(){
          ios::sync_with_stdio(0);
          cin.tie(0);
          cout.tie(0);
          for(ll i=1;i<=7;i++){
              cin>>a[i]>>b[i];
              ans=max(ans,a[i]+b[i]);
          }
          for(ll i=1;i<=7;i++){
              if(ans==a[i]+b[i]){
                  cout<<i;
                  return 0;
              }
          }
          return 0;
      }
      
      • 1
        @ 2023-10-15 14:58:42

        不说话,自己看(懒得写了

        #include <bits/stdc++.h>
        using namespace std;
        void areamax(int search[],int& n)/*int& n可以在函数内修改主函数的数*/
        {
            for(int i=1;i<=7;i++) /*判断数组里的数是否满足条件*/
            {
                if(n<search[i]&&search[i]>=8)     n=search[i];//如果是,那么n设为search[i]
            }
        }
        int main()
        {
            int sum[10];
            int x,y;
            for(int i=1;i<=7;i++)
            {
                cin>>x>>y;/*把上课时间和课外上课时间加起来*/
                sum[i]=x+y;
            }
            int Max=-1;
            areamax(sum,Max);//这个函数不用也可以(PS:作者习惯了)直接把函数的代码放入即可(注意修改函数内变量哦OwO)
            if(Max==-1)  cout<<0;/*如果Max还是初值,就认为津津不会不高兴*/
            else
            {
                for(int i=1;i<=7;i++)//否则搜索是哪天的上课时间等于Max
                {
                    if(sum[i]==Max){cout<<i; break;}
                }
            }
            return 0;
        }/*
          ^  ^
        =( owo)= <[给个赞再走!]
        [  U U ]
        [______]*/
        
        • 1
          @ 2023-10-10 21:03:54
          #include <bits/stdc++.h>
          using namespace std;
          int a[10];
          int l,r,maxn=-1;
          int main(){
          	for (int i=1;i<=7;i++){
          		cin>>l>>r;
          		if (l+r>8){//判断 
          			a[i]=l+r-8;//计算不高兴程度 
          		}
          		else{
          			a[i]=0;
          		}
          	}
          	for (int i=1;i<=7;i++){
          		maxn=max(maxn,a[i]);//计算最大 
          	}
          	if (maxn==0){
          		cout<<0;//没有不高兴的天数 
          		return 0;
          	}
          	for (int i=1;i<=7;i++){
          		if (a[i]==maxn){
          			cout<<i;
          			break;//计算最先 
          		}
          	}
          	return 0;
          }
          
          • 1
            @ 2022-9-23 21:17:16

            题前吐槽

            好多题解啊!!! 好简单的题啊!!!

            题解

            这道题是一道超级简单的模拟,就是要我们求7行中两个数相加是否大于8,没有大于8的就输出0,否则输出最大值的行号。 我们可以巧妙一些,初始让 pos=0pos = 0,当没有值大于8时,输出 pospos 也可以输出0,而如果有大于8的值时,更新最大值会随之更新 pospos,自然答案也是 pospos。 在编写代码时要注意输出第一个最大值行号,所以更新最大值和行号只在后一个严格大于前一个时更新。

            #include <bits/stdc++.h>
            using namespace std;
            int x, y, maxx = 8, pos = 0; // maxx最开始为8,因为只有不高兴了,x + y就会大于8,才能更新。如果maxx初始为0,那么小于等于8都会更新一下,pos就不会为0了
            int main()
            {
                for (int i = 1; i <= 7; i++)
                {
                    scanf("%d%d", &x, &y); // 7次输入
                    if (x + y > maxx) // 严格大于
                    {
                        // 更新值
                        maxx = x + y;
                        pos = i;
                    }
                }
                printf("%d\n", pos); // 输出
                return 0;
            }
            

            ACAC CodeCode

            #include <bits/stdc++.h>
            using namespace std;
            int x, y, maxx = 8, pos = 0;
            int main()
            {
                for (int i = 1; i <= 7; i++)
                {
                    scanf("%d%d", &x, &y);
                    if (x + y > maxx)
                    {
                        maxx = x + y;
                        pos = i;
                    }
                }
                printf("%d\n", pos);
                return 0;
            }
            
            • 1
              @ 2022-8-28 12:02:14

              [入门][NOIP2004普及组]不高兴的津津

              这题其实比较,算是比较的一题。 首先可以观察一下题干,先是然我们输入7行2列的数据。 那这里我们先用a,b来计数。 先用一个循环来输入数据,循环7次,每次读入a、b,之后每次更新津津不高兴的天数就完美解决了~ 上代码

              	int a, b, x = 0, y = 8;
              	for (int i = 1; i <= 7; i ++)
              	{
              		cin >> a >> b;
              		if (a+b > y)
              		{
              			y = a+b;	// 更新津津最不高兴的那一天的上课小时数 
              			x = i;	// 更新津津最不高兴的那一天 
              		}
              	}
              

              请独立思考,不要抄袭题解

              • 0
                @ 2023-10-11 19:44:57

                #include <bits/stdc++.h> using namespace std; struct happy{ int s,s1; }; happy a[10]; int b[10]; int main(){ for (int i=1;i<=7;i++){ cin>>a[i].s>>a[i].s1; b[i]=a[i].s+a[i].s1; } int maxn=-1,pos=0; for (int i=1;i<=7;i++){ if (maxn<b[i]){ maxn=b[i]; pos=i; } } cout<<pos; return 0; }

                • 0
                  @ 2023-7-5 15:01:56
                  #include <iostream>
                  using namespace std;
                  int ans, x, y, pos;
                  int main()
                  {
                      for (int i = 1; i <= 7; i++)
                      {
                          cin >> x >> y;
                          if (x + y > 8)
                              if (ans < x + y)
                              {
                                  ans = x + y;
                                  pos = i;
                              }
                      }
                      ans == 0 ? cout << 0: cout << pos;
                  }
                  
                  • 0
                    @ 2022-10-24 20:26:58
                    for (int i = 1; i <= 7; i++)
                        {
                            cin >> a >> b;
                            n = a + b;
                            if ((n > m) && (n > 8))
                            {
                                m = n;
                                angry_day = i;
                            }
                        }
                        cout << angry_day;
                        return 0;
                    }
                    

                    超级简单的模拟题

                    用a, b来计数。 再输入数据,循环7次,每次输入a、b, 更新津津不高兴的天数。

                    保证💯分

                    • 0
                      @ 2022-9-4 9:45:57

                      这题很水,直接看代码。

                      #include <bits/stdc++.h>
                      using namespace std;
                      int main()
                      {
                      	int a[10], b[10], c[10], maxn = -1, p = 0;
                      	for (int i = 1; i <= 7; i ++)
                      	{
                      		cin >> a[i] >> b[i];
                      		c[i] = a[i] + b[i];//记录每天总学习时长。
                      		if (c[i] > maxn)
                      		{
                      			p = i;//记录目前时间最长的位置(周几)。
                      			maxn = c[i];//把目前最大值换位当前值。
                      		}
                      	}
                      	if (maxn > 8)  cout << p;//最大值大于8就输出。
                      	else  cout << 0;//否则就没有大于8的。
                      }
                      

                      放心研究,已AC。 给个好评吧。

                      • -2
                        @ 2022-8-27 9:28:17

                        直接上AC代码!

                        • @ 2022-8-27 17:20:14

                          请不要直接发送AC代码,如果发现就会直接删除的哦~ 请遵守良好的学习环境。

                        • @ 2023-8-22 8:52:43

                          呵呵,六死了,大家都写光删我啊,@

                      • 1

                      [入门][NOIP2004 普及组] 不高兴的津津

                      信息

                      ID
                      1704
                      时间
                      1000ms
                      内存
                      256MiB
                      难度
                      2
                      标签
                      递交数
                      283
                      已通过
                      171
                      上传者