main.cpp

来自「acm icpc 重要学习资料 想参赛的同学必须练习的题目」· C++ 代码 · 共 70 行

CPP
70
字号
#include <iostream>
#include <vector>
#include <string>
using namespace std;

long func(long base,int i){
    int k;
    int tmp=1;
    for(k=i;k>0;--k)
        tmp=tmp*base;
    return tmp;
}

int main()
{
    //freopen("out.txt","w",stdout);
    //freopen("in.txt","r",stdin);
    string tmp;
    while(getline(cin,tmp)){
        if("0"==tmp) return 0;
        vector <long> num_p;
        long base,num_m;
        int pos;
        pos=tmp.find(32,0);
        base=atoi((tmp.substr(0,pos)).c_str());
        tmp.erase(0,pos+1);
        pos=tmp.find(32,0);
        long tmp_num=0;
        int i=tmp.size()-1;
        while(i>pos){
            tmp_num+=(tmp.at(i)-'0')*func(base,tmp.size()-i-1);
            //cout << tmp_num << "\t" ;
            i--;
        }
        num_m=tmp_num;
        i=pos-1;
        tmp_num=0;
        int j=0;
        while(i>=0){
            tmp_num+=(tmp.at(i)-'0')*func(base,(pos-i-1)%8);
            j++;
            if((tmp_num/10000000) || i==0){
                tmp_num=tmp_num*10+j;
                num_p.push_back(tmp_num);
                j=0;
                tmp_num=0;
            }
            i--;
        }
        i=num_p.size()-1;
        tmp_num=0;
        while(i>=0){
            //cout << tmp_num << "\t";
            tmp_num=tmp_num*func(10,num_p.at(i)%10+1)+num_p.at(i)/10;
            cout << num_p.at(i)/10 << "\t";
            int k=7;
            while(tmp_num < num_m && i>0 ){
                tmp_num=tmp_num*10+num_p.at(i-1)/func(10,k+1);
                num_p.at(i-1)=num_p.at(i-1)%func(10,k+1)-1;
                k--;
            }
            cout << tmp_num << "a" << endl;
            i--;
            //cout << tmp_num << endl;
            tmp_num%=num_m;
        }
        //cout << tmp_num << endl;
    }
	return 0;
}

⌨️ 快捷键说明

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