PDA

View Full Version : مشکل در حل سوال codechef



amin.net
چهارشنبه 11 اسفند 1395, 12:39 عصر
سلام. سوال زیر یکی از سوالات سطح مبتدی codechef.com هست:
Limak is a little polar bear, who loves eating cookies and drinking milk. For this reason he often visits Chef's kitchen.Limak is going to spend N minutes in the kitchen. Each minute he either eats a cookie or drinks milk. Cookies are very sweet and thus Limak's parents have instructed him, that after eating a cookie, he has to drink milk in the next minute.You are given whether he ate a cookie or drank milk in each of the N minutes. Your task is to check if Limak followed his parents' instructions. That is, you need to verify whether after each eaten cookie he drinks milk in the next minute. Print "YES" or "NO" for each test case accordingly.InputThe first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.The first line of each test case contains an integer N denoting the number of minutes.The second line of a test case contains N space-separated strings S1, S2, ..., SN. The string Si is either "cookie" (if Limak eats a cookie in the i-th minute) or "milk" (otherwise).OutputFor each test case, output a single line containing the answer — "YES" if Limak followed his parents' instructions, and "NO" otherwise, both without the quotes.Constraints

1 ≤ T ≤ 50
1 ≤ N ≤ 50
Each Si is either "cookie" or "milk" (without the quotes).

Subtasks

Subtask #1 (40 points) N = 2
Subtask #2 (60 points) Original constraints

ExampleInput:
4
7
cookie milk milk cookie milk cookie milk
5
cookie cookie milk milk milk
4
milk milk milk milk
1
cookie

Output:
YES
NO
YES
NOExplanationTest case 1. Limak is in the kitchen for 7 minutes. He eats three cookies and after each of them he indeed drinks milk in the next minute. The answer is "YES".Test case 2. Limak is in the kitchen for 5 minutes. In the first minute he eats a cookie and in the second minute he eats a cookie again, instead of drinking milk. The answer is "NO".Test case 3. Here Limak doesn't eat any cookies. The answer is "YES" because the condition is satisfied (there is no situation when Limak eats a cookie but doesn't drink milk in the next minute).Test case 4. Limak eats a cookie and doesn't drink milk in the next minute so the answer is "NO".

قطعه کد زیر هم چیزی هست که من نوشتم برای حل این مسئله:

#include <stdio.h>#include <stdlib.h>
#include <string.h>


#define TRUE 1
#define FALSE 0


int check(int row, int column, char s[row][column]){
int i = 0;


for(i = 0; i < row; i++){
if(s[i][0] == 'c'){
if(i == (row - 1))
break;
if(s[++i][0] == 'c')
return FALSE;
}
}
if(s[i-1][0] == 'm')
return TRUE;
else
return FALSE;
}


int main()
{
//variables
int i, j, T, N;
// char str[N][10];
// int answer[T];
//assignment
T = N = 0;


//operation
scanf("%d", &T);
int answer[T];
for(i = 0; i < T; i++){
scanf("%d", &N);
char str[N][10];
for(j = 0; j < N; j++){
scanf("%s", &str[j]);
}
answer[i] = check(N, 10, str);
}
//showing result
for(i = 0; i < T; i++){
if(answer[i] == TRUE)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}




تا جایی که خودم کامپایل کردم و تست زدم درست در میاد اما وقتی پاسخ رو submit میکنم بهم wrong answer میده. مشکل لطف کنین بگین مشکل کد کجاست؟