我需要左对齐显示 "Monday" 并且最高的列按降序出现在第一行

I need to display "Monday" with left justified and the highest columns appears in first row in descending order

应该是这样的输出:

星期一

当天

n天

y

我目前拥有的:

#include <iostream>
using namespace std;

int main () { char *weekDays[7]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"}; for (int i=0;i<7;i++){ cout << weekDays[0][i] << endl; } return 0; }

输出:

M o n d a y

我在移动,很累但是……这样应该可以工作:

int main(){recPrint(0);}

void recPrint(int level){
char mon[] = "Monday";
for(int i=level; i<strlen(mon); i++){
std::cout << mon[i];
} 
std::cout << std::endl;
recPrint(++level);
}

添加另一个参数 char dayOfTheWeek[],您可以随意调用它。

试试这个

#include <iostream>
using namespace std;

void display(char s[])
{
    int n = strlen(s);
    for(int i = 0; i < n; i++)
    {
        for(int j = i; j < n; j++)
        {
            cout << s[j];
        }
        cout << endl;
    }
}

int main () {
    char *weekDays[7]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};

   display(weekDays[0]);
}