社区讨论

为啥编译失败啊,devc++上可以运行啊

P1015[NOIP 1999 普及组] 回文数参与者 6已保存回复 6

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
6 条
当前快照
1 份
快照标识符
@lo55dqi5
此快照首次捕获于
2023/10/25 10:39
2 年前
此快照最后确认于
2023/11/02 11:29
2 年前
查看原帖
CPP
#include<string>
#include<iostream>
#include<stdlib.h>
#include<cstdio> 
using namespace std;
bool isHW(char* s){
	string temp;
	for(int i=0;s[i]!='\0';i++){
		temp.push_back(s[i]);
	}
	for(int i=0,j=temp.size()-1;i<j;i++,j--){
		if(temp[i]!=temp[j])return false;
	}
	return true;
}
int add(int n){
	int temp=n;
	int sum=0;
	while(temp!=0){
		sum=sum*10+temp%10;
		temp/=10;
	}
	return sum+n;
}
int main(){
	char s[200];
	int n,m;
	cin>>n>>m;
	int count=0;
	while(count<=30){
		itoa(m,s,n);
		if(isHW(s))break;
		m=add(m);
		count++;
	}
	if(count>30)cout<<"impossible!";
	else cout<<"STEP="<<count;
	return 0;
} 

回复

6 条回复,欢迎继续交流。

正在加载回复...