2 solutions

  • 0
    @ 2025-9-13 9:17:36

    先将7天对应的颜色赋值给一个数组(a),然后进行n次循环。每次循环都输入一次颜色(s)和天数(k),并把a数组遍历一遍,如果a数组当前下标位置等于s,就输出a[(j(下标)+k+1)%7]。

    using namespace std;
    int n, k;
    string s, a[7] = {"Purple", "Red",  "Orange", "Yellow", "Green", "Blue", "Cyan"};
    int main()
    {
    	cin >> n;
    	for (int i = 1;i <= n;i++)
    	{
    		cin >> s >> k;
    		for (int j = 0;j < 7;j++)
    		{
    			if (a[j] == s)
    			{
    				cout << a[(j + k + 1) % 7] << endl;
    			}
    		}
    	}
    	return 0;
    }
    
    
    
    • 0
      @ 2025-9-10 20:25:18
      #include <bits/stdc++.h>
      using namespace std;
      int n, k;
      string s, a[7] = {"Purple", "Red",  "Orange", "Yellow", "Green", "Blue", "Cyan"};
      int main()
      {
      	cin >> n;
      	for (int i = 1;i <= n;i++)
      	{
      		cin >> s >> k;
      		for (int j = 0;j < 7;j++)
      		{
      			if (a[j] == s)
      			{
      				cout << a[(j + k + 1) % 7] << endl;
      			}
      		}
      	}
      	return 0;
      }
      
      • 1

      Information

      ID
      1025
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      7
      Tags
      # Submissions
      39
      Accepted
      9
      Uploaded By