NOIP1996普及组

【NOIP1996普及组T2】棋盘填数

#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<map>
#define N 10000000
using namespace std;
int a[110];
int main(){
	int n,x,y;
	cin>>n>>x>>y;
	for(int i=1;i<=n;i++){
		cout<<"("<<x<<","<<i<<")";
	}
	cout<<endl;
	for(int i=1;i<=n;i++){
		cout<<"("<<i<<","<<y<<")";
	}
	cout<<endl;
	int xx=x,yy=y;
	while(xx>1&&yy>1) xx--,yy--;
	while(xx<=n&&yy<=n){
		cout<<"("<<xx<<","<<yy<<")";
		xx++;yy++;
	}
	cout<<endl;
	xx=x;yy=y;
	while(xx<n&&yy>1) xx++,yy--;
	while(xx>=1&&y<=n){
		cout<<"("<<xx<<","<<yy<<")";
		xx--;yy++;
	}
return 0;
}

  

1229 -- 【NOIP1996普及组T3】字符串编辑

从键盘输入一个字符串(长度<=40个字符),并以字符'.'结束.
例如:'This is a book.',现对该字符串进行编辑,编辑功能有:
D:删除一个字符,命令的方式为:
D a 其中a为被删除的字符
例如:D s 表示删除字符's',若字符串中有多个's',则删除第一次出现的,如上例中删除的结果为:
'Thi is a book.'
I:插入一个字符,命令的格式为:
I a1 a2 其中a1表示插入到指定字符前面,a2表示将要插入的字符
例如: I s d 表示在指定字符's'的前面插入字符'd',若原串中有多个's',则插入在最后一个字符的前面,
如上例中,原串:'This is a book.'
插入后:'This ids a book.'
R:替换一个字符,命令格式为:
R a1 a2 其中a1为被替换的字符,a2为替换的字符,若在原串中有多个a1,则应全部替换
例如:原串:'This is a book.'
输入命令: R o e
替换后:' This is a beek.'

这道题我记得改了几次都有问题TAT

#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<map>
#define N 10000000
using namespace std;

int main(){
	char a[50];
	char op,x,y;
	int n;
	bool flag=0;
	gets(a);
	for(int i=0;i<strlen(a);i++){
		if(a[i]=='.') flag=1;
		else if(flag){
			a[i]='.';
		}
 	}
	cin>>n;
	getchar();
	for(int i=1;i<=n;i++){
		op=getchar();
	if(op=='D'){
		getchar();
		x=getchar();
		//cout<<op<<" "<<x<<endl;
		for(int i=0;i<strlen(a)-1;i++){
			if(a[i]==x){
				for(int j=i+1;j<strlen(a);j++) a[j-1]=a[j];
				break;
			}
			
		}
	}
	else if(op=='I'){
		getchar();
		x=getchar();getchar();y=getchar();
		//cout<<op<<" "<<x<<" "<<y<<endl; 
		for(int j=strlen(a)-2;j>=0;j--){
			if(a[j]==x){
				for(int i=strlen(a)-1;i>j;i--) a[i]=a[i-1];
				a[j]=y;
				break;
			}
		}
	}
	else if(op=='R'){
		getchar();x=getchar();getchar();y=getchar();
		//cout<<op<<" "<<x<<" "<<y<<endl;
		for(int i=0;i<strlen(a);i++){
			if(a[i]==x) a[i]=y;
		}
	}
	getchar();
	}
	for(int i=0;i<strlen(a);i++){
		if(a[i]=='.') {
			cout<<a[i];
			break;
		}
		else cout<<a[i];
	}
	
return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/shirlybaby/p/12734631.html
今日推荐