Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一个H2O【146K 0ms】

Posted by KatrineYang at 2016-07-20 09:22:25 on Problem 1146
#include <stdio.h>
#include <cstring>
using namespace std;

int main() {
	while(1){
		char str[55] = {'\0'};
		scanf("%s", str);
		int len = strlen(str);
		//printf("%d\n", len);
		if(str[0] == '#') break;
		int pos = len - 1;
		while(pos >= 1 && str[pos] <= str[pos-1]){
			pos --;
		}
		//printf("%d\n", pos);
		if(pos == 0){
			printf("No Successor\n");
			continue;
		}
		char temp = str[pos - 1];
		int da;
		for(int i = len-1; ; i--){
			if(str[i] > temp){
				da = i;
				break;
			}
		}
		str[pos - 1] = str[da];
		str[da] = temp;
		for(int i = 0; i < pos; i++){
			printf("%c", str[i]);
		}
		for(int i = len-1; i >= pos; i--){
			printf("%c", str[i]);
		}
		printf("\n");
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator