24h購物| | PChome| 登入
2013-08-23 10:04:52| 人氣1,660| 回應0 | 上一篇 | 下一篇

[UVA][字串] 426 - Fifth Bank of Swamp County

推薦 0 收藏 0 轉貼0 訂閱站台


 Fifth Bank of Swamp County 

In response to overwhelming customer complaints, the Fifth Bank of Swamp County has finally decided to produce a listing of cleared checks at the end of each customer's checking account statement. The current statements list only the transaction history, sorted by date, which includes all deposits, withdrawals and fee assessments in addition to cleared checks. The code to generate the current statements was written by programmers with degrees in math; these programmers have for years argued that all ''necessary and sufficient'' information is contained in the transaction history, and any further output is unnecessary and wasteful. In order to minimize the cost of the software change, the bank has laid off the entire programming staff and has chosen instead to outsource the job to part-time student labor as a weekend project.

The cleared check summary will list all checks which cleared the bank during the statement reporting period. The summary will be sorted in ascending order by check number, and will report the dollar amount of the check and date the check cleared. To improve the usefulness of the list, any out-of-sequence check numbers should have an asterisk (*) printed next to them. An out-of-sequence check number is one which, when sorted, does not immediately succeed the previously cleared check number.

Input

The first line of the input will contain an integer N indicating the number of test case you need to test followed by a blank line.. Then there N set of test case. For each test input  to the check summary program consists of a check transaction history, sorted in ascending order by date. There will be one input line for each check, consisting of the transaction date in yy/mm/dd format, white space, the check number (an integer between 1 and 9999), white space, and the amount of the check in dollars and cents.

Consecutive test cases will separated by one blank line.

Output

The output for each test case should be displayed in three columns, with all checks sorted in column order (see the sample output). Do not print any more rows than necessary, and always fill the middle column before spilling over to the last column. Each column should be separated from the others by three spaces and have the following format:

nnnn* dddddd.cc yy/mm/dd

where ``nnnn'' is the check number with leading zeroes suppressed, ``*'' is the optional out-of-sequence indicator (use a space if in sequence), and ``dddddd.cc'' is the dollar and cent value of the check, with leading zeroes suppressed. If the check is for less than one dollar, print a zero before the decimal point. All checks for $1 million or more require special processing and are not handled through the bank's normal check clearing process; such checks will not appear on these statements.

Consecutive output is separated by single blank line.

Sample Input

1

93/10/01 998  .65
93/10/01 999 123.89
93/10/05 996 29.99
93/10/06 993 116.52
93/10/12 995 418.00
93/10/15 1001 15045.00
93/10/27 1000 840.85

Sample Output

 993     116.52 93/10/06    998*      0.65 93/10/01   1001   15045.00 93/10/15
 995*    418.00 93/10/12    999     123.89 93/10/01
 996      29.99 93/10/05   1000     840.85 93/10/27

題目描述:

應該是在記錄刷簿子時的處理,每次都會有記錄的 ID number 按照這個數字排序,輸出採用三欄方式。

然而有些數字不連續,例如範例輸入 993 跟 995 中間缺了一號,則在 995 那邊打個 *號。

討論區有幾組測資,後面沒有標記金額的,實際測資中不會有這種可能。


#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
struct E {
int yy, mm, dd;
int nnnn;
double dollar;
};
bool cmp(E a, E b) {
return a.nnnn < b.nnnn;
}
int main() {
int testcase;
scanf("%d", &testcase);
while(getchar() != '\n');
while(getchar() != '\n');
char s[1024];
E D[10005];
while(testcase--) {
int n, i = 0;
while(gets(s) && s[0] != '\0') {
sscanf(s, "%d/%d/%d %d %lf", &D[i].yy, &D[i].mm, &D[i].dd, &D[i].nnnn, &D[i].dollar);
i++;
}
n = i;
sort(D, D+n, cmp);
int div3 = n/3 + (n%3 != 0);
int asterisk[10005] = {};
for(i = 1; i < n; i++) {
if(D[i].nnnn != D[i-1].nnnn+1)
asterisk[i] = 1;
}
for(i = 0; i < div3; i++) {
printf("%4d%c %9.2lf %02d/%02d/%02d", D[i].nnnn, asterisk[i] ? '*': ' ', D[i].dollar, D[i].yy, D[i].mm, D[i].dd);
if(i+div3 < n)
printf(" %4d%c %9.2lf %02d/%02d/%02d", D[i+div3].nnnn, asterisk[i+div3] ? '*': ' ',
D[i+div3].dollar, D[i+div3].yy, D[i+div3].mm, D[i+div3].dd);
if(i+div3+div3 < n)
printf(" %4d%c %9.2lf %02d/%02d/%02d", D[i+div3*2].nnnn, asterisk[i+div3*2] ? '*': ' ',
D[i+div3*2].dollar, D[i+div3*2].yy, D[i+div3*2].mm, D[i+div3*2].dd);
puts("");
}
if(testcase)
puts("");
}
return 0;
}

台長: Morris
人氣(1,660) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 教育學習(進修、留學、學術研究、教育概況) | 個人分類: UVA |
此分類下一篇:[UVA] 570 - Stats
此分類上一篇:[UVA] 373 - Romulan Spelling

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文