社区讨论

有人和我一样写的吗?

AT_abc029_d [ABC029D] 1参与者 1已保存回复 0

讨论操作

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

当前回复
0 条
当前快照
1 份
快照标识符
@lp4v3fkd
此快照首次捕获于
2023/11/19 10:31
2 年前
此快照最后确认于
2023/11/19 12:15
2 年前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
int n,f[10];
int pd(int x){if(x==0) return 1;int tot=0;while(x){x/=10;tot++;}return tot;}
int front(int x){int num;while(x){num=x%10;x/=10;}return num;}
int main(){
	cin>>n;
	f[0]=f[1]=1;
	for(int i=2;i<=9;i++){f[i]=10*f[i-1]+int(pow(10,i-1));}
	int sum=0,l=1;
	while(true){
		if(pd(n)==1){if(n>=1){cout<<sum+1<<endl;break;}else{cout<<sum<<endl;break;}}
		if((pd(n)!=pd(l))){
			sum=sum+f[pd(n)-1];
			l=int(pow(10,pd(n)-1));
			continue;
	    }else{
	    	if(pd(n)==pd(l)&&front(l)==1&&front(n)==1){
	    		sum=sum+n-l+1;
	    		l=1;
	    		n-=int(pow(10,pd(n)-1));
	    		continue;
			}else{
				if(pd(n)==pd(l)&&front(l)==1&&front(n)!=1){
					sum=sum+int(pow(10,pd(l)-1))+f[pd(l)-1];
					l=l+int(pow(10,pd(l)-1));
					continue;
				}else{
					if(pd(n)==pd(l)&&front(l)!=1&&(front(l)!=front(n))){
						sum=sum+(front(n)-front(l))*f[pd(l)-1];
						l=int(pow(10,pd(n)-1))*front(n);
						continue;
					}else{
						if(pd(n)==pd(l)&&front(l)!=1&&(front(l)==front(n))){
							l=1;
	    	             	n=n-front(n)*int(pow(10,pd(n)-1));
	    	             	continue;
						}
					}
				}
			}
		}
	}
	return 0;
} 

回复

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

正在加载回复...