The following program is my ACcepted code for Codeforces -416A .
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃Codeforces 416A 的AC code!
Please feel free to use it after adding this blog as an reference. (http://autekroy.blogspot.tw)
If there is any mistake or comment, please let me know. :D
歡迎使用與分享任何內容,但請記得標示此部落格為出處。(http://autekroy.blogspot.tw/) 如果有發現任何的錯誤與建議請留言或跟我連絡。 : )
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃Codeforces 416A 的AC code!
歡迎一同討論學習,如有錯誤與任何建議請留言 : )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This program is for Codeforces 416A Guess a number! | |
//題目來源 Problem link: http://codeforces.com/problemset/problem/416/A | |
/** my mistakes from code on paper | |
compiler errers: | |
1. reduceRange(char[] oper) --> reduceRange (char* oper) | |
2. char[] reverseOper(char op) --> char* reverseOper(char* op) | |
3. declare function reverseOper after the function reduceRange | |
problem-solving logic: right | |
*/ | |
#include<stdio.h> | |
#include<string.h> | |
char* reverseOper(char* op) | |
{ | |
if(strcmp(op, "<") == 0) | |
return ">="; | |
if(strcmp(op, "<=") == 0) | |
return ">"; | |
if(strcmp(op, ">") == 0) | |
return "<="; | |
if(strcmp(op, ">=") == 0) | |
return "<"; | |
} | |
void reduceRange(char* oper, int num, char ans, int& Max, int& Min) | |
{ | |
if(ans == 'N') | |
oper = reverseOper(oper); | |
if(strcmp(oper, "<") == 0){ | |
if(Max > (num - 1)) | |
Max = (num - 1); | |
} | |
else if(strcmp(oper, "<=") == 0){ | |
if(Max > num) | |
Max = num; | |
} | |
else if(strcmp(oper, ">") == 0){ | |
if(Min < (num + 1)) | |
Min = (num + 1); | |
} | |
else if(strcmp(oper, ">=") == 0){ | |
if(Min < num) | |
Min = num; | |
} | |
} | |
int main() | |
{ | |
int n, Max, Min, num; | |
char oper[3], ans; | |
while(scanf("%d", &n) != EOF) | |
{ | |
Max = 2e9; | |
Min = -2e9; | |
while(n--) | |
{ | |
scanf("%s %d %c", &oper, &num, &ans); | |
reduceRange(oper, num, ans, Max, Min); | |
} | |
//printf("%d\t%d\n", Min, Max); | |
if(Min > Max) | |
printf("Impossible\n"); | |
else | |
printf("%d\n", Min); | |
} | |
return 0; | |
} |
歡迎使用與分享任何內容,但請記得標示此部落格為出處。(http://autekroy.blogspot.tw/) 如果有發現任何的錯誤與建議請留言或跟我連絡。 : )
沒有留言:
張貼留言
請留下您的任何想法或建議!
Please leave any thought or comment!