1007(附带取各位数字的算法).txt

来自「KMP字符串匹配的c实现」· 文本 代码 · 共 52 行

TXT
52
字号
#include<iostream.h>
#include<math.h>


int main(){
	const int d=9;
	int n;
	int N;
	int pn9;
	int pn10;
	int t;
	int temp;
	int tempN;
	int a;
	while(cin>>n&&n){
		N=100000000;
		pn9=0;
		pn10=0;
		while(n<N){
			N/=10;
		}
		cout<<n<<": ";
		tempN=N;
		
		while(N){ //,5,6,7,8,9->4,5,6,7,8,
			temp=n/N;
			if(temp>4)
				--temp;
			pn9+=temp*N;
			n%=N;
			N/=10;
		}
		t=0; 
		a=pn9; //????pn9????
		while(a){//????????????
			t++;
			a/=10;
		}
	
	   
		while(tempN){    //9????->10????
			pn10=pn10+(pn9/tempN)*(pow(d,--t));
			pn9%=tempN;
			tempN/=10;
		}
		
		cout<<pn10<<endl;
	}
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?