#include<stdio.h>
int main()
{
int i, p[5], a, b, c, x, y = 20;
for ( i = 0; i <= 4; i++ )
scanf( "%d", &p[i] );
a = (p[0] + p[1]) + (p[2] + p[3] + p[4]) / 7;
b = p[0] + p[1] / ( (p[2] + p[3]) / p[4]);
c = p[0] * p[1] / p[2];
x = a + b - p[(p[3] + 3) % 4];
if ( x > 10 )
y += (b * 100 - a) / (p[p[4] % 3] * 5);
else
y += 20 + (b * 100 - c) / (p[p[4] % 3] * 5);
printf( "%d,%d\n", x, y );
return(0);
}
//注:本例中,给定的输入数据可以避免分母为 0 或数组元素下标越界。
#include "math.h"
#include "stdio.h"
int main()
{
int a1[51] = { 0 };
int i, j, t, t2, n = 50;
for ( i = 2; i <= sqrt( n ); i++ )
if ( a1[i] == 0 )
{
t2 = n / i;
for ( j = 2; j <= t2; j++ )
a1[i * j] = 1;
}
t = 0;
for ( i = 2; i <= n; i++ )
if ( a1[i] == 0 )
{
printf( "%4d", i ); t++;
if ( t % 10 == 0 )
printf( "\n" );
}
printf( "\n" );
}
#include "ctype.h"
#include "stdio.h"
void expand( char s1[], char s2[] )
{
int i, j, a, b, c;
j = 0;
for ( i = 0; (c = s1[i]) != '\0'; i++ )
if ( c == '-' )
{
a = s1[i - 1]; b = s1[i + 1];
if ( isalpha( a ) && isalpha( b ) || isdigit( a ) && isdigit( b ) )
/*函数 isalpha(a) 用于判断字符 a 是否为字母,isdigit(b) 用于判断字符 b 是否为数字,如果是,返回 1,否则返回 0 */
{
j--;
do
s2[j++] = a++;
while ( tolower( a ) < tolower( s1[i + 1] ) );
}
/*函数 tolower(a) 的功能是当字符 a 是大写字母,改为小写,其余情况不变*/
else s2[j++] = c;
}else s2[j++] = c;
s2[j] = '\0';
}
int main()
{
char s1[100], s2[300];
printf( "input s1:" );
gets( s1 );
expand( s1, s2 );
printf( "%s\n", s2 );
}
#include <iostream.h>
#include <string.h>
int maxline = 200, kz;
int reverse( char s[] )
{
int i, j, t;
for ( i = 0, j = strlen( s ) - 1; i < j; 【①】 , 【②】 )
{
t = s[i]; s[i] = s[j]; s[j] = t;
}
return(0);
}
int main()
{
char line[100];
cout << "continue? -1 for end." <<endl;
cin>>kz;
while(【③】)
{
cin >> line;
【④】;
cout << line << endl;
cout << "continue ? -1 for end." << endl;
cin >> kz;
}
}
2 2 3 3
2 -1 1 3
4 1 1 5
4 4 5 5
#include <iostream.h>
#include <iomanip.h>
int board[65][65], tile; /* tile为纸片编号 */
void chessboard( int tr, int tc, int dr, int dc, int size )
/* dr,dc依次为特殊方格的行、列号 */
{
int t, s;
if ( size == 1 )
① ;
t = tile++;
s = size / 2;
if ( ② )
chessboard( tr, tc, dr, dc, s );
else{
board[tr + s -1][tc + s -1] = t;
[③];
}
if ( dr < tr + s && dc >= tc + s )
chessboard( tr, tc + s, dr, dc, s );
else{
board[tr + s -1][tc + s] = t;
④;
}
if ( dr >= tr + s && dc < tc + s )
chessboard( tr + s, tc, dr, dc, s );
else{
board[tr + s][tc + s -1] = t;
[⑤];
}
if ( dr >= tr + s && dc >= tc + s )
chessboard( tr + s, tc + s, dr, dc, s );
else{ board[tr + s][tc + s] = t;
[⑥]; }
}
void prtl( int b[][65], int n )
{
int i, j;
for ( i =1; i <= n; i++ )
{
for ( j =1; j <= n; j++ )
cout << setw( 3 ) << b[i][j];
cout << endl;
}
}
void main()
{
int size, dr, dc;
cout << "input size(4/8/16/64):" << endl;
cin >> size;
cout << "input the position of special block(x,y):" << endl;
cin >> dr >> dc;
board[dr][dc] = -1;
tile++;
chessboard( 1, 1, dr, dc, size );
prtl( board, size );
}