#include <stdio.h> int main() { char line[100]; int num_tests, n, m, x, y; char h, v; while (1) { fgets(line, 100, stdin); sscanf(line, "%d", &num_tests); if (num_tests == 0) { return 0; } fgets(line, 100, stdin); sscanf(line, "%d %d", &n, &m); for (int i = 0; i < num_tests; ++i) { fgets(line, 100, stdin); sscanf(line, "%d %d", &x, &y); if (x == n || y == m) { printf("divisa\n"); continue; } if (x > n) { h = 'E'; } else { h = 'O'; } if (y > m) { v = 'N'; } else { v = 'S'; } printf("%c%c\n", v, h); } } return 0; }
Showing posts with label code. Show all posts
Showing posts with label code. Show all posts
Thursday, August 2, 2012
11498: Division of Nlogonia
Thought about reviving this blog. I visited UVa Online Judge today and they have a lot of new problems since I last visited it. I tried looking for an easy problem and this is what I found. Here is a sample C++ code solution that got accepted:
Labels:
11498,
algorithm,
C++,
code,
Division of Nlogonia,
solution,
UVA Online Judge
Monday, December 29, 2008
UVa problem 11364: sample code
001 #include "stdio.h"
002 #include "stdlib.h"
003
004 int main() {
005 char line[100]
006 , ctmp[100]
007 ;
008 int num_tests
009 , num_stores
010 , stores[100]
011 , itmp
012 , max
013 , min
014 , diff
015 , i
016 , j
017 , k
018 , m
019 ;
020
021 fgets(line, 100, stdin);
022 sscanf(line, "%d\n", &num_tests);
023
024 for (i = 0; i < num_tests; i += 1) {
025 fgets(line, 100, stdin);
026 sscanf(line, "%d\n", &num_stores);
027
028 fgets(line, 100, stdin);
029 for (j = 0, m = 0; 1; j += 1) {
030 if (line[j] == '\n' || line[j] == 0) {
031 break;
032 }
033
034 if (line[j] == ' ' || line[j] == '\t') {
035 continue;
036 }
037
038 for (k = 0; 1 ; j += 1, k += 1) {
039 if (line[j] == ' ' || line[j] == '\t' || line[j] == '\n' || line[j] == 0) {
040 break;
041 }
042 ctmp[k] = line[j];
043 }
044 ctmp[k] = 0;
045
046 stores[m] = atoi(ctmp);
047 m += 1;
048 }
049
050 max = 0;
051 min = 99;
052 for (j = 0; j < num_stores; j += 1) {
053 if (stores[j] > max) {
054 max = stores[j];
055 }
056
057 if (stores[j] < min) {
058 min = stores[j];
059 }
060 }
061 diff = max - min;
062 diff *= 2;
063
064 printf("%d\n", diff);
065 }
066
067 return 0;
068 }
Labels:
11364,
code,
parking,
problem,
sample solution,
UVA Online Judge
Sunday, December 28, 2008
UVa Online Judge
The UVa Online Judge (http://icpcres.ecs.baylor.edu/onlinejudge/) is a website that archives thousands of problems used for computer programming competitions. It also provides a facility for validating code submissions to the problems published. Hence, it offers an excellent venue for testing algorithms.
Each problem in the archive is tagged with an ID number for easy identification. Refer to Figure 1.

Figure 1. Problems listing in the archive.
In Figure 1, the problem “Moscow time” has an ID number of 505.
Codes can be submitted for online validation can be written in C, Java, C++ or Pascal. Figure 2 shows the form for online submission.

Figure 2. Form for online code submission.
To search for a problem, one can opt to use the Google search bar as shown in Figure 3.
Each problem in the archive is tagged with an ID number for easy identification. Refer to Figure 1.
Figure 1. Problems listing in the archive.
In Figure 1, the problem “Moscow time” has an ID number of 505.
Codes can be submitted for online validation can be written in C, Java, C++ or Pascal. Figure 2 shows the form for online submission.
Figure 2. Form for online code submission.
To search for a problem, one can opt to use the Google search bar as shown in Figure 3.
Simply type in the problem ID in the Google bar. Be sure to tick the icpcres.ecs.baylor.edu button.
Subscribe to:
Posts (Atom)