#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int n;
cin>> n;
for ( int i= 1 ; i<= n; i++ )
{
string space= string ( n- i, ' ' ) ;
string ch= string ( 2 * i- 1 , 'A' + i- 1 ) ;
cout<< space+ ch<< endl;
}
return 0 ;
}
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
char c;
cin>> c;
if ( c>= 'A' && c<= 'Z' )
{
for ( int i= 1 ; i<= c- 'A' + 1 ; i++ )
{
for ( int j= 1 ; j<= c- 'A' + 1 - i; j++ )
cout<< " " ;
for ( int j= 1 ; j<= i; j++ )
cout<< char ( 'A' + j- 1 ) ;
for ( int j= i- 1 ; j>= 1 ; j-- )
cout<< char ( 'A' + j- 1 ) ;
cout<< endl;
}
}
else {
for ( int i= 1 ; i<= c- '1' + 1 ; i++ )
{
for ( int j= 1 ; j<= c- '1' + 1 - i; j++ )
cout<< " " ;
for ( int j= 1 ; j<= i; j++ )
cout<< char ( '1' + j- 1 ) ;
for ( int j= i- 1 ; j>= 1 ; j-- )
cout<< char ( '1' + j- 1 ) ;
cout<< endl;
}
}
return 0 ;
}
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int n, m;
cin>> n>> m;
for ( int i= 1 ; i<= n; i++ )
{
for ( int j= 1 ; j<= m; j++ )
cout<< "+-" ;
cout<< "+" << endl;
for ( int j= 1 ; j<= m; j++ )
cout<< "l*" ;
cout<< "l" << endl;
}
for ( int i= 1 ; i<= m; i++ )
cout<< "+-" ;
cout<< "+" << endl;
return 0 ;
}
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
char name[ 10 ] ;
char * str= "abcde" ;
strcpy ( name, str) ;
cout<< name<< endl;
return 0 ;
}
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
char str[ 25 ] ;
char * str1= "abc" , * str2= "def" , * str3= "ghl" ;
strcat ( str, str1) ;
strcat ( str, str2) ;
strcat ( str, str3) ;
cout<< str<< endl;
return 0 ;
}
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
char * str1= "fabc" , * str2= "def" ;
int res= strcmp ( str1, str2) ;
if ( res> 0 )
cout<< str1<< " is greater than" << str2<< endl;
else if ( res== 0 )
cout<< str1<< "is same as" << str2<< endl;
else
cout<< str1<< "is less than " << str2<< endl;
return 0 ;
}
#include <bits/stdc++.h>
using namespace std;
char res[ 5000000 ] ;
int main ( )
{
int n;
cin>> n;
int len= 0 ;
for ( int i= 1 ; i<= n; i++ )
{
strcat ( res+ len+ 1 , res) ;
res[ len] = 'A' + i- 1 ;
len= strlen ( res) ;
}
cout<< res<< endl;
return 0 ;
}
fgets(数组名,数组长度-1,stdin)//非常好用!!!
#include <bits/stdc++.h>
using namespace std;
char s1[ 1005 ] , s2[ 1005 ] ;
int main ( )
{
fgets ( s1, 1004 , stdin ) ;
fgets ( s2, 1004 , stdin ) ;
int len1= strlen ( s1) - 1 , len2= strlen ( s2) - 1 ;
int ans= 0 ;
for ( int i= 0 ; i+ len2- 1 < len1; i++ )
{
bool matched= true ;
for ( int j= 0 ; j< len2; j++ )
if ( s1[ i+ j] != s2[ j] )
{
matched= false ;
break ;
}
if ( matched)
ans++ ;
}
cout<< ans<< endl;
return 0 ;
}
int is_leap_year ( int year)
{
if ( year% 400 == 0 || ( year% 100 != 0 && year% 4 == 0 ) )
return 1 ;
return 0 ;
}
#include <bits/stdc++.h>
using namespace std;
int whatday ( int y, int m, int d)
{
int ans= 0 ;
for ( int i= 1 ; i< y; i++ )
{
if ( i% 400 == 0 || ( i% 4 == 0 && i% 100 != 0 ) )
{
ans+ = 366 % 7 ;
ans% = 7 ;
}
else
{
ans+ = 365 % 7 ;
ans% = 7 ;
}
}
for ( int i= 1 ; i< m; i++ )
{
if ( i== 2 )
{
if ( y% 400 == 0 || ( y% 4 == 0 && y% 100 != 0 ) )
{
ans+ = 29 % 7 ;
ans% = 7 ;
}
else
{
ans+ = 28 % 7 ;
ans% = 7 ;
}
}
else if ( i== 4 || i== 6 || i== 9 || i== 11 )
{
ans+ = 30 % 7 ;
ans% = 7 ;
}
else
{
ans+ = 31 % 7 ;
ans% = 7 ;
}
}
ans+ = ( d- 1 ) % 7 ;
ans% = 7 ;
return ans;
}
string weekday[ 7 ] = { "Monday" , "Tuesday" , "wednesday" , "Thursday" , "Friday" , "saturday" , "sunday" } ;
int main ( )
{
int y, m, d;
cin>> y>> m>> d;
cout<< weekday[ whatday ( y, m, d) ] << endl;
return 0 ;
}
#include <bits/stdc++.h>
using namespace std;
int main ( )
{
int day[ 13 ] = { 0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ;
int y, m, d, k;
cin>> y>> m>> d>> k;
for ( int i= 1 ; i<= k; i++ )
{
if ( y% 400 == 0 || ( y% 4 == 0 && y% 100 != 0 ) )
day[ 2 ] = 29 ;
d++ ;
if ( d== day[ m] + 1 )
{
d= 1 ;
m++ ;
}
if ( m== 13 )
{
m= 1 ;
y++ ;
}
}
cout<< y<< m<< d<< endl;
return 0 ;
}
#include <bits/stdc++.h>
using namespace std;
int day[ 13 ] = { 0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ;
int mm[ 10 ] = { 1 , 5 , 10 , 10 , 10 , 12 } ;
int dd[ 10 ] = { 1 , 1 , 1 , 2 , 3 , 25 } ;
void nextday ( int & m, int & d)
{
d++ ;
if ( d== day[ m] + 1 )
{
d= 1 ;
m++ ;
}
}
int main ( )
{
int y, m= 1 , d= 1 , ans= 0 , sf= 0 , w;
cin>> y;
if ( y% 400 == 0 || y% 4 == 0 && y% 100 != 0 )
{
day[ 2 ] ++ ;
}
for ( int i= 6 ; i< 10 ; i++ )
{
cin>> mm[ i] >> dd[ i] ;
}
cin>> w;
while ( m< 13 )
{
if ( mm[ 6 ] == m&& dd[ 6 ] == d)
{
sf= 2 ;
ans++ ;
}
else if ( sf)
{
ans++ ;
sf-- ;
}
else if ( w== 6 || w== 7 )
ans++ ;
else {
for ( int i= 0 ; i< 10 ; i++ )
{
if ( mm[ i] == m&& dd[ i] == d)
{
ans++ ;
break ;
}
}
}
nextday ( m, d) ;
w++ ;
if ( w== 8 )
w= 1 ;
}
cout<< ans<< endl;
return 0 ;
}
C++的语言习惯可以和C做切换,哪个方便用哪个------ scanf("%s",s);
#include <bits/stdc++.h>
using namespace std;
char s[ 105 ] ;
int main ( )
{
int ans= 0 ;
scanf ( "%s" , s) ;
for ( int i= 0 ; i< strlen ( s) ; i++ )
{
if ( s[ i] == 'A' )
ans++ ;
}
cout<< ans<< endl;
return 0 ;
}
#include <bits/stdc++.h>
using namespace std;
char s[ 105 ] , ans[ 105 ] ;
int maxans= 0 ;
int main ( )
{
int n;
cin>> n;
int len;
for ( int i= 0 ; i< n; i++ )
{
scanf ( "%s" , s) ;
len= strlen ( s) ;
if ( len> maxans)
{
maxans= len;
strcpy ( ans, s) ;
}
}
cout<< ans<< endl;
return 0 ;
}
#include <bits/stdc++.h>
using namespace std;
char s[ 10005 ] ;
int main ( ) {
int len;
scanf ( "%s" , s) ;
len= strlen ( s) ;
for ( int i= 0 ; i< len; i++ ) {
if ( s[ i] == 'z' ) s[ i] = 'a' ;
else if ( s[ i] == 'Z' ) s[ i] = 'A' ;
else if ( s[ i] >= 'a' && s[ i] <= 'z' || s[ i] >= 'A' && s[ i] <= 'Z' )
s[ i] ++ ;
}
cout<< s<< endl;
return 0 ;
}
#include <bits/stdc++.h>
using namespace std;
char s[ 10005 ] ;
int main ( ) {
int len;
scanf ( "%s" , s) ;
len= strlen ( s) ;
if ( ( s[ len- 1 ] - '0' % 2 == 0 )
cout<< "yes" << endl;
else
cout<< "no" << endl;
return 0 ;
}
#include <bits/stdc++.h>
using namespace std;
char s[ 10005 ] ;
int main ( ) {
int len;
scanf ( "%s" , s) ;
for ( int i= strlen ( s) - 1 ; i>= 0 ; i-- )
cout<< s[ i] ;
cout<< endl;
return 0 ;
}
EOF: 在黑框中手动输入时,系统并不知道什么时候到达了所谓的“文件末尾“,因此需要先按< Enter >键,再用< Ctrl + Z >组合键,然后按< Enter >键的方式来告诉系统已经到了 EOF,这样系统才会结束 while。 补充积累:EOF(end of file)就是文件的结束,通常来判断文件的操作是否结束的标志。EOF不是特殊字符,而是定义在头文件<stdio.h>的常量,一般等于-1;除了文件结束,做题遇见最多的是标准输入,但是标准输入与文件不一样,无法事先知道输入的长度,必须手动输入一个字符,表示到达EOF;Linux中,在新的一行的开头,按下Ctrl-D,就代表EOF(如果在一行的中间按下Ctrl-D,则表示输出“标准输入”的缓存区,所以这时必须按两次Ctrl-D);Windows中,Ctrl-Z表示EOF。
#include <bits/stdc++.h>
using namespace std;
char s[ 10005 ] ;
int main ( ) {
while ( scanf ( "%s" , s) != EOF ) ;
cout<< strlen ( s) << endl;
return 0 ;
}