NOIP2007 初赛试题(普及组 C++)

 

 

 

#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 );
}

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值