[URI ONLINE JUDGE] – 1766 – The Dark Elf

The stable where the reindeers were was intentionally opened by the Dark Elf allowing each of them to run and fly freely around the Santa Claus’ factory, causing the greatest disorder. The elves are desperately trying to do everything possible to let the sled ready for departure. You are responsible for putting each reindeer in its correct position so that it is captured by one of the other elves.

You know the stable follows an organization based on the order that the reindeers will occupy the sled. Thus, at the time of departure all of them can be easily positioned. Unlike what you may think, the reindeers are placed in a single queue ahead in the sled. Not all reindeers in the stable are used on each trip, that depends on the total load of the sled.

You got the list with all the characteristics that are used to determine the reindeer order. They must first be sorted by the descending order of weight. If two or more have the same weight they should be sorted in ascending order by age and height, if the tie still remains, order by name.

Using your last generation magical computer you want to write a program to order the reindeers according to informed characteristics and display only the exact number of reindeers that will be used by the sled (in an orderly manner).

Input

This problem has several test cases. The first line of the input contains an integer T (1 ≤ T ≤ 105) that indicates the number of test cases that follows. The first line of each test case contains two integers Nand M (5 ≤ N, M ≤ 103) respectively indicating the total number of reindeers and the number of reindeers that will pull the sleigh. In the next lines it will be informed an string S followed by two integers W (1 ≤ W≤ 300) and A (1 ≤ A ≤ 300) and a floating point number H (0.00 ≤ H ≤ 3.00), indicating the name, weight, age and height of each raindeer.

Output

For each test case you should print the message “CENARIO {i}” where i indicates the current test case followed by the position and the name of each of the M reindeer that will pull the sleigh, ordered as described above.

Input Sample Output Sample
1
9 5
Rudolph 50 100 1.12
Dasher 10 121 1.98
Dancer 10 131 1.14
Prancer 7 142 1.36
Vixen 50 110 1.42
Comet 50 121 1.21
Cupid 50 107 1.45
Donner 30 106 1.23
Blitzen 50 180 1.84
CENARIO {1}
1 – Rudolph
2 – Cupid
3 – Vixen
4 – Comet
5 – Blitzen

my solution:


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cctype>
#include <string.h>

#define SC1(a) scanf("%d", &a)
#define SC2(a, b) scanf("%d %d", &a, &b)
#define ZERO(x) memset(x, 0, sizeof(x))
#define FOR(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef struct
{
char no[101];
int pe, id;
float al;
}rena;

rena arr[10010];

bool compare_strings (char * c1, char * c2)
{
int sz = (strlen(c1) > strlen(c2) ? strlen(c1) : strlen(c2));

for (int i = 0; i < sz; ++i)
{
if(c1[i] < c2[i]) return true;
if(c1[i] > c2[i]) return false;
}

return true;
}

bool cmp(rena a, rena b)
{
if(a.pe == b.pe){
if(a.id == b.id){
if(a.al == b.al){
if(compare_strings(a.no, b.no)) return a.no > b.no;
else return a.no < b.no;
}else{
return a.al > b.al;
}
}else{
return a.id > b.id;
}
}else{
return a.pe < b.pe;
}
}

int main(int argc, char const *argv[])
{
int t, n, m, c = 1;

SC1(t);

while(t--)
{
SC2(n, m);
ZERO(arr);

FOR(i, n)
cin >> arr[i].no >> arr[i].pe >> arr[i].id >> arr[i].al;

stable_sort(arr, arr + n, cmp);
reverse(arr, arr + n);

printf("CENARIO {%d}\n", c);
c++;

FOR(i, m)
{
printf("%d - ", (i + 1));
cout << arr[i].no << endl;
}
}

return 0;
}

[URI ONLINE JUDGE] – 1249 – Rot13

Write a program that receives a secret message, and returns this coded message. The message is encrypted with a cipher called rot13. Rot13 works as follows, for each letter is assigned an index, based on its position in the alphabet. a = 1, b = 2, c = 3, …, z = 26. Each letter of the message should be moved 13 places to the right, if the end of the alphabet is reached, the count starts at the first character of the alphabet. For example, the character “a” (quotes only to exemplify) would be mapped to “n”, “y” to “l”, “f” to “s”, and so on. The same process is also made to uppercase. Any non-alphabetic characters must be transferred to the output unchanged.

Input

The input consist in many test cases. Each test case is composed by a line that contains a message with at least 1 up to 50 characters including, containing letters, numbers, and the following symbols: !@#$%^&*()-_=+[]{}|;’:,./<>?”

Output

For each line of input, print a line in the output with the message encoded in the rot13 method.

Sample Input Sample Output
z
a
x
Hello world!
This is a test message.
abc123<>,xyz?*$
m
n
k
Uryyb jbeyq!
Guvf vf n grfg zrffntr.
nop123<>,klm?*$

My solution:


#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

char l[] = "abcdefghijklmnopqrstuvwxyzabcdefghijklm";
char u[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLM";

char rot13(char c){
int i;

for (i = 0; i <= 25; i++){
if (c == l[i]){
return l[i + 13];
}
}
for (i = 0; i <= 25; i++){
if (c == u[i]){
return u[i + 13];
}
}
return c;
}

int main(){
char c;
while((c = getchar()) != EOF){
cout << rot13(c);
}
return 0;
}

Lập trình trên Windows – 2

Tổng quan MFC
– Dùng Visual C++ 6 hoặc các bản Visual Studio
*THƯ VIỆN MFC:
– Thư viện các lớp, oop.
– Khi báo afxwin.h.
– Có các hàm toàn cục (các hàm có prefix là afx…).
– Gọi các hàm api dùng toán tử định phạm vi (::).

CÁC LOẠI FILE DO APPWIZARD SINH RA
phải có include “stdafx.h” trong mỗi file .cpp
SDI:
Lớp cơ sở:
+ CWinApp
+ CDocument
+ CView
+ CFrameWnd
Lớp dẫn xuất:
+ CBTApp
+ CBTDoc
+ CBTView
+ CMainFrame
File nguồn:
+ BT.cpp
+ BTDoc.cpp
+ BTView.cpp
+ MainFrm.cpp
File header:
+ BT.h
+ BTDoc.h
+ BTView.h
+ MainFrm.h
*MDI:
Lớp cơ sở:
+ CWinApp
+ CDocument
+ CView
+ CMDIFrameWnd
+ CMDIChildWnd
Lớp dẫn xuất:
+ CBTApp
+ CBTDoc
+ CBTView
+ CMainFrm
+ CChildFrm
File nguồn:
+ BT.cpp
+ BTDoc.cpp
+ BTView.cpp
……………
…………
File header:
+ BT.h
+ BTDoc.h
+ BTView.h
…………….
……………

LỚP APPLICATION
– Tên lớp là CWinApp.
khởi động (init) -> chạy (run) -> kết thúc.
– Chứa vòng lặp nhận message loop
– Mỗi ứng dụng có 1 và chì 1 đối tượng dẫn xuất từ lớp CWinApp (đối tượng này thường tên là theApp).
+ InitInstance() (khởi tạo instance). –> Run() (message loop ẩn dưới hàm run)—>exitInstance() (kết thúc ứng dụng).
*hàm updateWindows(): biến vùng client thành invalidate –> sinh ra WM_PAINT
LỚP CDOCUMENT:
– Chức năng là lưu dữ liệu
LỚP VIEW:
– Tên lớp là CView
– Quản lý hiển thị. (hàm onDraw đảm nhiệm cv này)
– Truyền / nhận thông tin sang lớp document.
Lớp FRAME:
– Lóp này mặc định là CMainFrame
– Tạo quản lý cửa sổ, toolbar, menu bar..
– Nó là cửa sổ mức cao nhất.

+SDI: CMainFrame dẫn xuất từ CMainWnd–> Tưởng tượng nếu bỏ phần client ra thì còn lại là main window.
+ MDI: tưởng tượng nếu như tắt cửa sổ con bên trong -> còn lại main frame. ….được dẫn xuất từ CMDIFrameWnd……………. CChildFrame dẫn xuất từ CMDIChildWnd……. gọi là MDI child frame window………….. Các window frame chứa các view.
*KIẾN TRÚC DOCUMENT/VIEW:
– Cốt lõi của ap MFC là:
đối tượng document lo việc lưu và nạp dữ liệu…. đối tượng lo việc trình bày..
– Mối tương quan giữa document và view là quan hệ 1 chiều –> 1 view gắn với 1 document.
– Để gắn chặt document, view và frame. MFC dùng document template

  • Lớp View có thể truy cập tới dữ liệu của document thông qua hàm CView::getDocument().
    thông thường sử dụng qua biến con trỏ CDocument:
    CBTView::onDraw(…){
    CDocument* p;
    p = new ……;
    }
  • Cập nhật lại tất cả các view dùng hàm updateAllView(NULL);
    (1) Tạo project có tên là “BaiTap” dạng SDI
    (2) Thêm biến vào lớp CBaiTapDoc như sau: kiểu CString, tên m_Hello, access modifier là public.

Hiệu chỉnh constructor của lớp CBT01Doc
m_Hello = _T(“xin chao”);
// _T: gọi là macro để tùy biến hoặc asscii hoặc unicode.

Chỉnh hàm onDraw()
pDc->Textout(10, 10, pDc->m_Hello);
XỬ LÝ MESSAGE TRONG MFC
thông qua hàm xử lý message gọi là mesage handler

WM_PAINT: OnPaint()
WM_SIZE: OnSize()
… các message handler có tên prefix là on…..
Mặc định OnPaint() sẽ tự động gọi OnDraw().
LỚP CSCROLLVIEW
chọn lớp cơ sở là CScrollView thay vì CView.
Để xác định kích thước theo đơn vị logic, ta chỉnh hàm ảo OnInitUpdate()

void OnInitUpdate()
SizeTotal có thể set khác 100
để thiết lập lấy vị trí của scrollview: CScrollView::getScrollPosition()….
………..

IntelliJ IDEA 14.1 Ultimate

Supported only in Ultimate Edition:
  • Database Tools — SQL Editor, Schema Definition Editor, Diagrams.
  • UML Designer — Analysis, Modelling, Refactorings
  • HTML, CSS
  • JavaScript, CoffeeScript, TypeScript
  • ActionScript
  • Freemarker, Velocity
  • XSL, XPath
  • Spring Framework — Core, MVC, WebFlow, Web Service, Data, Security, Integration, Roo, etc.
  • Java EE — Servlets, JSP, JSF, Web Services, CDI, Bean Validation, etc.
  • JPA, Hibernate — Completion, Navigation, Refactorings, Queries, Diagrams, etc.
  • GWT — Google Web Toolkit
  • Vaadin
  • Grails
  • Play Framework — Play 1.x and Play 2.x
  • JBoss Seam
  • SQL — PostgreSQL, MySQL, Oracle, Microsoft SQL Server, etc.
  • Ruby, JRuby — available via a plugin.
  • Python — available via a plugin.
  • PHP — PHPUnit, Smarty, etc.. available via a plugin.
  • Struts — Struts 1.x and Struts 2.x
  • Griffon
  • AspectJ
  • Thymeleaf
  • Tapestry
  • Sass, LESS, Stylus, Compass
  • Rails, RubyMotion — available via a plugin.
  • Node.js — available via a plugin.
  • Django — available via a plugin.
  • Adobe Flex, AIR — including AIR Mobile for iOS and Android.
  • IBM WebSphere
  • Geronimo
  • Resin
  • Jetty
  • Virgo

Download: 

Installer

key

  1. Download the installer.
  2. Disconnect to the internet.
  3. Install & use the key above.

Cheers.
David Ng

[URI Online Judge] – 1024 – Encryption

You have been asked to build a simple encryption program. This program should be able to send coded messages without someone been able to read them. The process is very simple. It is divides into two parts.

First, each uppercase or lowercase letter must be shifted three positions to the right, according to the ASCII table: letter ‘a’ should become letter ‘d’, letter ‘y’ must become the character ‘|’ and so on. Second, each line must be reversed. After being reversed, all characters from the half on (truncated) must be moved one position to the left in ASCII. In this case, ‘b’ becomes ‘a’ and ‘a’ becomes ‘`’.

For example, if the resulting word of the first part is “tesla”, the letters “sla” should be moved one position to the left. However if the resulting word of the first part is “t#$A”, the letters “A$” are to be displaced.

Input

The input contains a number of test cases. The first line of each test case contains an integer N (1 ≤ N ≤ 1 * 10⁴), indicating the number of lines the problem should encrypt. The following N lines contains Mcharacters each M (1 ≤ M ≤ 1 * 10³).

Output

For each test case, you must present the encrypted message.

Sample Input Sample Output
4
Texto #3
abcABC1
vxpdylY .ph
vv.xwfxo.fd
3# rvzgV
1FECedc
ks. \n{frzx
gi.r{hyz-xx

my solution:


#include <iostream>
// #include <cstdio>

using namespace std;

int main(){
int n;
string s;

cin >> n;
getline(cin, s);

while(n--){
getline(cin, s);

string r(s.rbegin(), s.rend());

unsigned int l = r.length();

for (unsigned int i = 0; i < s.length(); ++i){
if ((r.at(i) >= 65 && r.at(i) <= 90) || (r.at(i) >= 97 && r.at(i) <= 122)){
r.at(i) = r.at(i) + 3;
}
if (i >= l / 2){
r.at(i) = r.at(i) - 1;
}
}

cout << r << endl;
}

return 0;
}