0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

複数の文字列を辞書順に並び替える方法

Posted at

注意

AtcoderのB - Qualification Contestのネタバレあり

ACしたコード

//写経#38610740
#include<stdio.h>
#include<string.h>

int main(void) {
	int N,K;
	char str[100][11];
	char tmp[100];

	scanf("%d%d", &N,&K);

	for (int i = 0; i < N; i++)
	{
		scanf("%s", str[i]);

	}

	for (int i = 1; i < N; i++) {
		for (int j = 1; j < K; j++) {
			if (strcmp(str[j - 1], str[j]) > 0) {
				strcpy(tmp, str[j - 1]);
				strcpy(str[j - 1], str[j]);
				strcpy(str[j], tmp);
			}
		}
	}
	for (int i = 0; i < K; i++)
	{
		printf("%s\n", str[i]);
	}
	return 0;
}

参考にした記事まとめ

文字列の配列を用意し、標準入力から読み込んだ文字列を表示するプログラム
文字列を辞書順に並べる

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?