Submission #36438493
Source Code Expand
#include <stdio.h>
void swap (int *x, int *y);
int partition (int array[], int left, int right);
void quick_sort (int array[], int left, int right);
int main(void){
int flag = 1; // 1:Yes
int n;
scanf("%d", &n);
int deck[n];
char card[3];
for(int i = 0; i < n && flag; i++){
scanf("%s", card);
deck[i] = 0;
switch(card[0]){
case 'H':
deck[i] += 0 * 13;
break;
case 'D':
deck[i] += 1 * 13;
break;
case 'C':
deck[i] += 2 * 13;
break;
case 'S':
deck[i] += 3 * 13;
break;
default:
flag = 0;
break;
}
switch(card[1]){
case 'A':
deck[i] += 1;
break;
case 'T':
deck[i] += 10;
break;
case 'J':
deck[i] += 11;
break;
case 'Q':
deck[i] += 12;
break;
case 'K':
deck[i] += 13;
break;
default:
if(card[1] >= '2' && card[1] <= '9'){
deck[i] += card[1] - 48;
}
else{
flag = 0;
}
break;
}
}
quick_sort(deck, 0, n-1);
/*
for(int i = 0; i < n; i++){
printf("%d ", deck[i]);
}
*/
for(int i = 0; i < n-1; i++){
if(deck[i] == deck[i+1]){
flag = 0;
break;
}
}
if(flag){
printf("Yes\n");
}
else{
printf("No\n");
}
return 0;
}
/* 値を入れ替える関数 */
void swap (int *x, int *y) {
int temp; // 値を一時保存する変数
temp = *x;
*x = *y;
*y = temp;
}
/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
int i, j, pivot;
i = left;
j = right + 1;
pivot = left; // 先頭要素をpivotとする
do {
do {
i++;
} while (array[i] < array[pivot]);
do {
j--;
} while (array[pivot] < array[j]);
// pivotより小さいものを左へ、大きいものを右へ
if (i < j) {
swap(&array[i], &array[j]);
}
} while (i < j);
swap(&array[pivot], &array[j]); //pivotを更新
return j;
}
/* クイックソート */
void quick_sort (int array[], int left, int right) {
int pivot;
if (left < right) {
pivot = partition(array, left, right);
quick_sort(array, left, pivot-1); // pivotを境に再帰的にクイックソート
quick_sort(array, pivot+1, right);
}
}
Submission Info
Submission Time
2022-11-12 22:05:42+0900
Task
B - Playing Cards Validation
User
Cebu
Language
C (GCC 9.2.1)
Score
200
Code Size
2386 Byte
Status
AC
Exec Time
3 ms
Memory
1632 KiB
Compile Error
./Main.c: In function ‘main’:
./Main.c:11:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
11 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
./Main.c:15:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
15 | scanf("%s", card);
| ^~~~~~~~~~~~~~~~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
200 / 200
Status
Set Name
Test Cases
Sample
example0.txt, example1.txt, example2.txt, example3.txt
All
example0.txt, example1.txt, example2.txt, example3.txt, max0.txt, random0.txt, random1.txt, random10.txt, random11.txt, random12.txt, random13.txt, random2.txt, random3.txt, random4.txt, random5.txt, random6.txt, random7.txt, random8.txt, random9.txt
Case Name
Status
Exec Time
Memory
example0.txt
AC
2 ms
1580 KiB
example1.txt
AC
1 ms
1632 KiB
example2.txt
AC
1 ms
1604 KiB
example3.txt
AC
1 ms
1588 KiB
max0.txt
AC
1 ms
1592 KiB
random0.txt
AC
1 ms
1596 KiB
random1.txt
AC
1 ms
1628 KiB
random10.txt
AC
2 ms
1632 KiB
random11.txt
AC
2 ms
1596 KiB
random12.txt
AC
1 ms
1552 KiB
random13.txt
AC
2 ms
1556 KiB
random2.txt
AC
2 ms
1604 KiB
random3.txt
AC
1 ms
1572 KiB
random4.txt
AC
1 ms
1592 KiB
random5.txt
AC
1 ms
1552 KiB
random6.txt
AC
3 ms
1628 KiB
random7.txt
AC
1 ms
1588 KiB
random8.txt
AC
1 ms
1572 KiB
random9.txt
AC
2 ms
1484 KiB