# Calendar format output problem written by c++, to solve the ah, do a few days

```#include <iostream>
#include <iomanip>
using namespace std;
char* weekd={"Day "," a "," two "," three "," four "," Five "," six"};
bool Isrunnian(int n)
{
if(n%400==0||(n%4==0&&n%100!=0))
return true;
else
return false;
}
int weekday(int a)
{
int n=(a+(a-1)/4-(a-1)/100+(a-1)/400)%7;//Calculation of a new year's day for the week n
return n+1;
}
int monthday(int i) //Here is the return month of a few days, I month
{
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
return    31; //If it is 1,2,5,7,8,10,12 month, the return is 31 days
else if (i==2) //Judge in February
if(Isrunnian(i)) //When 1 returns is a leap year, for 29 days
return    29;
else return 28; //Otherwise 28 days
else
return    30; //Rest for 30 days
}
void show1(int a)
{
int i,j;
int n=weekday(a);
for(i=1;i<=12;i++)
{
cout<<"                    ";
int lemp=1;
cout<<setw(16)<<i<<"Month";
cout<<endl;
cout<<"                    ";
for (j=0;j<7;j++)
cout<<setw(5)<<weekd[j];
cout<<endl;
cout<<"                    ";
for(int k=1;k<n;k++,lemp++)      //Input the first day of the month starting position, with the space added
cout<<setw(5)<<" ";   //Is if it's Thursday, there are 3 spaces in front, 1 from Thursday's position
for(int d=1;d<=monthday(i);d++,lemp++) //The output cycle days of each month
{
cout<<setw(5)<<d;    //D is the day
if(lemp==7)          //The control line of output to Sunday to Sunday, if re count
{
cout<<endl; //Is Saturday's words just outputs a newline
cout<<"                    ";
lemp=0;          //Let the temporary recording week variables for 0, to prepare for the next use
}
}
n=lemp%7;       //When the output end of a month later, recording the last day of the month in which, looking for the next month.
if(n==0)        //The starting position of the first day
n=7;//When n is 0, is Sunday, so n is 7
cout<<endl;
}
}```

It is the output of the

Started by Ron at February 08, 2016 - 11:45 PM It is the output format
Can be based on a code change

Posted by Ron at February 16, 2016 - 12:20 AM

Chinese output format change on the line
cout<<setw(6)<<weekd[j];
You try

Posted by Elsa at February 27, 2016 - 1:03 AM

Not do it

Posted by Ron at March 09, 2016 - 1:04 AM

Hungry, you was wrong

Using a two-dimensional array on the line,

Posted by Elsa at November 18, 2016 - 6:39 PM

First of all output in a two-dimensional array of characters which, finally according to order the output of the character array.

Posted by Cornelius at November 30, 2016 - 7:37 PM

For reference only:
```#pragma warning(disable:4786)
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main () {
wstring ws1,ws2;

wcin.imbue(locale("chs"));
wcout.imbue(locale("chs"));
getline(wcin,ws1);
getline(wcin,ws2);
if (ws1.size()!=ws2.size()) {
wcout<<ws1<<L" And "<<ws2<<not corresponding to L""<<endl;
return 1;
}

map<wchar_t,wchar_t> m1,m2;
int n=ws1.size();

for (int i=0;i<n;i++) {
if (m1.find(ws1[i])==m1.end() && m2.find(ws2[i])==m2.end()) {
m1[ws1[i]]=ws2[i];
m2[ws2[i]]=ws1[i];
} else {
if (m1[ws1[i]]!=ws2[i] || m2[ws2[i]]!=ws1[i]) {
wcout<<ws1<<L" And "<<ws2<<not corresponding to L""<<endl;
return 1;
}
}
}
wcout<<ws1<<L" And "<<ws2<<L" correspondence"<<endl;
return 0;
}
```

Posted by Cornelius at December 05, 2016 - 8:28 PM

Posted by Ron at December 15, 2016 - 9:03 PM

```#include <iostream>
#include <iomanip>
using namespace std;
char* week_name="Day one two three four five six";
bool Isrunnian(int n)
{
if(n%400==0||(n%4==0&&n%100!=0))
return true;
else
return false;
}
int weekday(int a)
{
int n=(a+(a-1)/4-(a-1)/100+(a-1)/400)%7;//Calculation of a new year's day for the week n
return n+1;
}
int monthday(int i) //Here is the return month of a few days, I month
{
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
return    31; //If it is 1,2,5,7,8,10,12 month, the return is 31 days
else if (i==2) //Judge in February
if(Isrunnian(i)) //When 1 returns is a leap year, for 29 days
return    29;
else return 28; //Otherwise 28 days
else
return    30; //Rest for 30 days
}

#define FIELD_WIDTH 5
#define LINE_WIDTH (FIELD_WIDTH*7)
#define LINE_NUMBER 8
typedef char month_map_t[LINE_NUMBER][LINE_WIDTH+1];
month_map_t calender;
void compose_calender(int a)
{
int i,j;
int n=weekday(a);
memset(calender, ' ', sizeof(calender));
for(i=1;i<=12;i++)
{
month_map_t *p_month_map = &calender[i-1];
sprintf(&(*p_month_map), "%2D month", i);
(*p_month_map)[strlen((*p_month_map))] = ' ';
strcpy((*p_month_map), week_name);
(*p_month_map)[strlen((*p_month_map))] = ' ';
int lemp=n;
char *q = (*p_month_map) + (n-1)*FIELD_WIDTH;
int l = 3;
for(int d=1;d<=monthday(i);d++,lemp++) //The output cycle days of each month
{
sprintf(q, "%2d", d); //cout<<setw(5)<<d;    //D is the day
q[strlen(q)] = ' ';
q += FIELD_WIDTH;
if(lemp==7)          //The control line of output to Sunday to Sunday, if re count
{
q = (*p_month_map)[l++];
lemp=0;          //Let the temporary recording week variables for 0, to prepare for the next use
}
}
n=lemp%7;       //When the output end of a month later, recording the last day of the month in which, looking for the next month.
if(n==0)        //The starting position of the first day
n=7;//When n is 0, is Sunday, so n is 7
for (j = 0; j <LINE_NUMBER; j++)
(*p_month_map)[j][LINE_WIDTH] = '\0';
}
}

int main()
{
int i, j;

compose_calender(1);

//According to the original format output
for (i = 0; i <12; i++)
{
for (j = 0; j <LINE_NUMBER; j++)
{
printf("%s\n", calender[i][j]);
}
printf("\n");
}

//According to the new format.
for (j = 0; j <LINE_NUMBER; j++)
{
for (i = 0; i <12; i++)
{
printf("%s  ", calender[i][j]);
}
printf("\n");
}

//Also according to other output formats. . . . . .

}```

Posted by Myron at December 21, 2016 - 9:26 PM

To remind you to use wcout Chinese characters processing

Posted by Cornelius at January 01, 2017 - 9:47 PM

Well, good, thank you

Posted by Ron at January 05, 2017 - 10:25 PM

Is excuse me, how much is the definition of a 2 dimension group size?

Posted by Ron at January 05, 2017 - 11:02 PM

```#include <stdio.h>

int main(void)
{
int a, i, j, n, k, t, w, x, y, z;
static int d;   //Why is here defined for this 2 dimensional array??? No idea
int m = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char wst[] = " Sun Mon Tue Wed Thu Fri Sat   ";
scanf("%d", &y);

if(y%4==0 && y%100!=0 || y%400==0)  /*Leap year in February for 29 days*/
m = 29;
w = (y+(y-1)/4-(y-1)/100+(y-1)/400)%7; /*Calculation of y New Year's day for the week w*/
for(i=1; i<=12; i++)   //Month
{
a = 1;     //Record date
for(j=1; j<=6; j++)
{
for(k=0; k<=6; k++)
{
while(k<w) k=k+1; //For example, in 2013 yuan Dan for week 2, namely w=2
d[i][j*10+k] = a;  /*Calculation of the I of the j a week of the date for a w*/
a++;
w++;
if(w==7) w=0;
if(a>m[i]) break;
}
if(a>m[i]) break;
}
}```

There is above a few cycle also cannot read it d[i][j*10+k] = a;

Posted by Ron at January 09, 2017 - 10:26 PM