結果
| 問題 | No.39 桁の数字を入れ替え |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-05-13 21:54:41 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 2,109 bytes |
| 記録 | |
| コンパイル時間 | 380 ms |
| コンパイル使用メモリ | 31,744 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-02 07:20:01 |
| 合計ジャッジ時間 | 1,001 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define READ_BUFSIZE ( 1024 )
#define READ_DELIMITER ( " " )
//標準入力取得(1行)
int GetStdin( char* pszStr, int lMaxLen )
{
int lLen = 0;
memset( pszStr, 0, lMaxLen );
if( fgets( pszStr, lMaxLen, stdin ) )
{
lLen = strlen( pszStr );
if( lLen >= 1 )
{
if( pszStr[ lLen - 1 ] == 0x0A )
{
pszStr[ lLen - 1 ] = 0;
lLen--;
}
}
}
return( lLen );
}
//標準入力を取得
//区切り文字で区切られている文字列を取り出す
//取り出した文字列のポインタをポインタ配列にセットする (文字列型)
int split(char *pszStr, int lStrMax, const char *pszDelim, char *apszOutList[]) {
char *pszToken;
int count = 0;
char *pszNext_token = 0;
int lLen = 0;
int lNum = 0;
memset(pszStr, 0, lStrMax);
lLen = GetStdin(pszStr, lStrMax);
if (lLen > 0)
{
pszToken = strtok(pszStr, pszDelim);
while (pszToken != NULL)
{
apszOutList[lNum] = pszToken;
lNum++;
// pszToken = strtok_s(NULL, pszDelim, &pszNext_token);
pszToken = strtok(NULL, pszDelim);
}
}
return lNum;
}
void swap(char &i, char &j)
{
char k = i;
i = j;
j = k;
}
//文字列のソート バブルソート(降順)
void sort(char* pInput, int lLength)
{
for (int i = 0; i < lLength; i++)
{
for (int j = lLength - 1; j >= i + 1; j--)
{
if (pInput[j] > pInput[j - 1])
swap(pInput[j], pInput[j - 1]);
}
}
}
int main(int argc, char *argv[])
{
char szRead[READ_BUFSIZE] = "";
//int OutList[1] = { 0 };
//char* pOutList[2] = {0};
int len = GetStdin( szRead, READ_BUFSIZE);
//int N = atoi(pOutList[0] );
char szChar[10] = "";
char szSort[10] = "";
strcpy(szChar, szRead);
strcpy(szSort, szRead);
sort(szSort, len);
//先頭から比較
int i = 0;
for (i = 0; i < len; i++)
{
if (szChar[i] != szSort[i])
break;
}
//後ろから検索
for (int j = len - 1; j >= 0; j--)
{
if (szSort[i] == szChar[j])
{
swap(szChar[i], szChar[j]);
break;
}
}
printf("%s\n", szChar);
return 0;
}