1 条题解

  • 0
    @ 2021-6-15 1:39:06

    C++ :

    #include<iostream>
    #include<string>
    #include<cstring>
    using namespace std;
    int s, t, w;
    string num;
    bool hasNext(int i, char c) {
    	if (c>=('a'+t-1-(w-1-i))) return false;
    	else return true;
    }
    void changeLater(int i) {
    	for (i++; i < w; i++)
    		num[i] = num[i-1]+1;
    }
    void next() {
    	for (int i = w-1; i >= 0; i--) {
    		if (hasNext(i, num[i])) {
    			num[i] = num[i]+1;
    			changeLater(i);
    			break;
    		}
    	}
    	cout << num << endl;
    }
    int main() {
    	while (cin >> s >> t >> w) {
    		cin >> num;
    		for (int i = 0; i < 5; i++)
    			next();
    	}
    	return 0;
    }
    

    Pascal :

    var s,t,w,i,j,k:longint;str:string;
    begin
      readln(s,t,w);
      readln(str);
      for i:=1 to 5 do
        begin
          j:=w;
          while (j>0)and(ord(str[j])-96=t-(w-j)) do dec(j);
          if j=0 then break;
          str[j]:=chr(ord(str[j])+1);
          for k:=j+1 to w do str[k]:=chr(ord(str[k-1])+1);
          writeln(str);
        end;
    end.
    
    • 1

    信息

    ID
    248
    时间
    1000ms
    内存
    125MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者