PAT乙级 部分题目解答(仅是记录自己的学习过程,有错误欢迎指正)

 (本次包括所有15分值的题目与个别20分的题目,仅为记录自己的代码方便翻看。当让如果能帮助到你最好了。)

刷题要先有自己的想法与实现,然后debug,还是有通不过的测试用例则可以查看其他同学的实现,是个很好的过程。

加油。

 

#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;

int main(){
	char str[81];
	gets(str); //gets() 可以读取空格,但是不会接受换行符;
                   //getline()可以接受换行符,所以getline()之后还需要getchar()来吸收\n 
	int i = 0;
	for(i=strlen(str); i>0; --i){
		if(str[i] == ' '){
			printf("%s ",&str[i+1]);//读取i处空格后的整个单词字符串 
			str[i] = '\0';//讲空格处改为\0,这样之后的字符串输出才能在空格处结束 
		}
	} 
	printf("%s",&str[i]);//以字符串的格式输出,从str[i]的地址开始直到遇到\0 
	return 0;
}

 

#include<iostream>

using namespace std;

int main(){
	int M;
	cin >> M;
	int a;
	for(int i=0; i<M; ++i)
	{
		cin >> a;
		int flag;
		for(int N=1; N<10; ++N)
		{
			flag = 1;
			int rst = N * a * a;
			//cout << rst << endl;
			int t1 = rst;
			int t2 = a;
			while(t2){
				
				int r1 = t2%10;
				int r2 = t1%10;
				if(r1 != r2){
					flag = 0;
				}
				t2 /= 10;
				t1 /= 10; 
			}
			if(flag == 1){
				cout << N << " " << rst << endl;
				break;
			}
		}
		if(flag == 0) {
				cout << "No" << endl;
			}
	}
	return 0;
}

#include<iostream>

using namespace std;

int main(){
	int A,B;
	cin >> A >> B;
	int R = A * B;
	if(R==0){
		cout << "0";
	}
	int flag = 0; 
	int tmp = 0;
	while(R!=0)//容易忽略的情况,当第一个0出现时不输出,
                   //但是输出第一个不为零的数后,之后的零就必须输出 
	{
		tmp = R % 10;
		if((tmp != 0) && (flag == 0)){
			cout << tmp;
			flag = 1;
		}
		else if(flag == 1){
			cout << tmp;
		}
		R = R / 10;
	}
	cout << endl;
	return 0;
}

#include<iostream>
#include<string.h> 
#include<cctype>
//#include<string>

using namespace std;

/*分析:非空字符串,每个字符串以回车结束,但是
        字符串里面可能会有空格,所以不能直接用cin,
		要用getline接收一行字符。在接收完n后要getchar()
		读取一下换行符才能用getline,否则换行符会被读进getline中
*/
int main()
{
	int N;
	//string str[101];
	cin >> N;
	getchar();
	for(int i=0; i<N; ++i){
		string str;
		int flag_n = 0, flag_c = 0, flag_oth = 0;
		//cin >> str;
		//int len = 0;
		//const string temp = str[i];
		
		getline(cin,str);
		int len = str.length();
		if(len < 6){
			cout << "Your password is tai duan le." << endl;
			continue;
		}
		for(int j=0; j<len; ++j)
		{
			if(isdigit(str[j])){
				flag_n = 1;
			}
			else if((str[j]<='z') && (str[j]>='A')){
				flag_c = 1;
			}
			else if(str[j]!='.' && !isalnum(str[j])){
				flag_oth = 1;
			}
		}
		//cout << flag_n << flag_c << flag_oth << endl;
		if(flag_oth == 1){
			cout << "Your password is tai luan le." << endl;
		}
		else if(flag_n == 0){
			cout << "Your password needs shu zi." << endl;
		}
		else if(flag_c == 0){
			cout << "Your password needs zi mu." << endl;
		}
		else{
			cout << "Your password is wan mei." << endl;
		}
	} 
	return 0;
}

#include<iostream>
#include<string.h>
//#include<stdlib.h>
using namespace std;

int main(){
	int N;
	cin >> N;
	char a,b; 
	for(int i=0; i<N; ++i)
	{
		for(int j=0; j<4; ++j)
		{
			scanf("%c-%c ",&a,&b);
			if(a=='A' && b=
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值