阅读程序 普及篇(1-8题)

1、【NOIP1998】第三章 阅读程序 第2节 普及篇(B)

#include <bits/stdc++.h> 
#include <iostream>
#include <cstdio>
using namespace std;
int i,j;
int i_1,j_1;
int k,s,t,s1,l,swapp;
const int n=4;
char temp,a[n*2+1];
int main( )
{
	for(int i=1;i<=2*n;++i) a[i]=getchar();
	s=0;t=0;
	for(int i=1;i<=n*2;++i)
		if( a[i]=='1') s++;
		else if( a[i]=='0') t++;
	if( s!=n || t!=n ) printf("error");
	else
	{
		s1=0;
		for(int i=1;i<=2*n-1;++i)
			if( a[i]!=a[i+1]) s1++;
		printf("jamp=%d\n",s1);
		swapp=0;
		for(int i=1;i<=2*n-1;++i)
		for(int j=i;j<=2*n;++j)
			if( a[i]!=a[j])
			{
				temp=a[i];a[i]=a[j];a[j]=temp;
				s=0;
				for(int l=1;l<=2*n-1;++l)
				{
					if( a[l]!=a[l+1]) s++;
				}
				if( s>swapp )
				{
					swapp=s;i_1=i;j_1=j;
				}
				temp=a[i];a[i]=a[j];a[j]=temp;
			}
			if( swapp>0 ) printf("maxswap=%d i=%d j=%d",swapp-s1,i_1,j_1);
	}
	return 0;
}
/*
输入:10101100
输出:
答案: 
jamp=5
maxswap=2 i=6 j=7
--------------------------------
Process exited after 7.797 seconds with return value 0
请按任意键继续. . .
*/

阅读程序 普及篇 2、【NOIP1999】

https://blog.csdn.net/dllglvzhenfeng/article/details/130978120

阅读程序 普及篇 3、【NOIP1999】

https://blog.csdn.net/dllglvzhenfeng/article/details/130978815

阅读程序 普及篇 4、【NOIP2000】

https://blog.csdn.net/dllglvzhenfeng/article/details/130978932

阅读程序 普及篇 5、NOIP2001

阅读程序 普及篇 5、【NOIP2001】_dllglvzhenfeng的博客-CSDN博客

第三章 阅读程序 第2节 普及篇 6、【NOIP2001】

https://blog.csdn.net/dllglvzhenfeng/article/details/130917098


7、NOIP2002 第三章 阅读程序 第2节 普及篇(C)

#include <iostream>
#include <cstdio>
using namespace std;
int a[21],i,j,k,n,l0,l1,lk,num=0;
int main( )
{
	scanf("%d%d",&n,&k);
	for(i=0;i<=n-1;++i) a[i]=i+1;
	a[n]=a[n-1];
	
	l0=n-1;
	lk=n-1;
	for(i=1;i<=n-1;++i)
	{
		l1=l0-k;
		if( l1<0 ) l1=l1+n;
		if( l1==lk)
		{
			a[l0]=a[n];
			lk=lk-1;
			a[n]=a[lk];
			l0=lk;
		}
		else
		{
			a[l0]=a[l1];
			l0=l1;
		}
	}
	a[l0]=a[n];
	cout<<num<<endl;
	for(i=0;i<=n-1;++i) printf("%4d",a[i]);
	printf("\n");
	return 0;
}
/*
程序的功能,将1-n循环右移k位 
输入:10 4
输出:
答案:7 8 9 10 1 2 3 4 5 6
*/ 

8、NOIP2002

#include <stdio.h>
#include <cstdio>
using namesapce std;
int a[11],i,j,s,sp1;
bool p;
int main(){
    sp1=1;
    a[1]=2;
    j=2;
    while(sp1<10){
        j++;
        p=true;
        for(i=2;i<=j-1;i++)
            if(j%i==0) p=false;
        if(p){//开始将该段if放在for循环中,答案不对,后将该段if移出for循环,答案正确
            sp1++;
            a[sp1]=j;
        }
    }
    j=2;
    p=true;
    while(p){
        s=1;
        for(i=1;i<=j;i++)  s*=a[i];
        s++;
        for(i=2;i<=s-1;i++)
            if(s%i==0) p=false;
        j++;
    }
    printf("%d\n",s);
    return 0;
}
/*
输出:
答案:30031
*/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dllglvzhenfeng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值