大体题意:
给你n 场oj的比赛,告诉你每一次比赛的名字,和每一次比赛总共的题数,在告诉你他的做题情况 打出一个表来!
思路:
这个题目坑不多,也不是很难,但自己就是没有做出来,通过这个题目自己长了不少教训!!!!
思路很简单了,建立一个结构体,有标题,和总体数,和每一道题目是否做出来,-1表示没做,0 表示做错,1表示AC,最后统计即可!
教训:
1. 首先对于字符串有空格的情况,scanf之后gets之前虽然要加getchar,但是一定要统揽全局来看,因为有的样例 不循环,导致循环之内的scanf 没有运行,就会因为少了一个getchar出错!
对于这种情况 很简单, 直接每次scanf后加上%*c即可! 可以吃掉回车,这样可以紧接着写gets!
2. 不用gets,用getline 或者fgets 尽量用fgets!
为了安全,gets少用,因为其没有指定输入字符的大小,限制输入缓冲区得大小,如果输入的字符大于定义的数组长度,会发生内存越界,堆栈溢出。后果非常严重!
fgets会指定大小,如果超出数组大小,会自动根据定义数组的长度截断。
之前就是一道题目因为用了gets 怎么改都是WA 换了fgets AC了!!!
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<sstream>
#define fout freopen("out.txt","w",stdout)
#define fi first
#define se second
#define mr make_pair
using namespace std;
const int maxn = 1000 + 10;
struct Node{
string title;
int y,d,m;
int ok[26];
int sum;
void init(){
memset(ok,-1,sizeof ok);
y = d = m = 0;
title = "";
}
}p[107];
char ans[107];
int main(){
int n;
scanf("%d%*c",&n);
for (int kase = 0; kase < n; ++kase){
p[kase].init();
getline(cin,p[kase].title);
scanf("%d.%d.%d%*c",&p[kase].d,&p[kase].m,&p[kase].y);
int m,q;
scanf("%d %d%*c",&m,&q);
p[kase].sum = m;
char cmd[5];
for (int i = 0; i < q; ++i){
scanf("%s%*c",cmd);
fgets(ans,maxn,stdin);
cmd[0] = toupper(cmd[0]);
int id = cmd[0] - 'A';
if (ans[0] == 'A')p[kase].ok[id] = 1;
else if (p[kase].ok[id] <= 0)p[kase].ok[id] = 0;
}
}
printf("+------------------------------+--------+-------------+\n");
printf("|Contest name |Date |ABCDEFGHIJKLM|\n");
for (int i = 0; i < n; ++i){
printf("+------------------------------+--------+-------------+\n");
printf("|%s",p[i].title.c_str());
int len = p[i].title.length();
for (int i = len; i < 30; ++i)printf(" ");
printf("|%02d.%02d.%02d|",p[i].d,p[i].m,p[i].y);
int en = 'M'-'A'+1;
for (int j = 0; j < p[i].sum; ++j){
if (p[i].ok[j] == 1)printf("o");
else if (p[i].ok[j] == 0)printf("x");
else printf(".");
}
for(int j = p[i].sum; j < en; ++j)printf(" ");
puts("|");
}
printf("+------------------------------+--------+-------------+\n");
return 0;
}
2073. Log Files
Time limit: 1.0 second
Memory limit: 64 MB
Nikolay has decided to become the best programmer in the world! Now he regularly takes part in various programming contests, attentively listens to problems analysis and upsolves problems. But the point is that he had participated in such a number of contests that got totally confused, which problems had already been solved and which had not. So Nikolay conceived to make a program that could read contests’ logs and build beautiful summary table of the problems. Nikolay is busy participating in a new contest so he has entrusted this task to you!
Input
The first line contains an integer n (1 ≤ n ≤ 100). It‘s the number of contests‘ descriptions. Then descriptions are given. The first line of description consists of from 1 to 30 symbols — Latin letters, digits and spaces — and gives the name of contest. It‘s given that the name doesn‘t begin and doesn’t end with a space. In the second line of description the date of contest in DD.MM.YY format is given. It‘s also given that the date is correct and YY can be from 00 to 99 that means date from 2000 till 2099. In the third line of description there are numbers p and sseparated by space (1 ≤ p ≤ 13, 0 ≤ s ≤ 100). It‘s amount of problems and Nikolay’s submits in the contest. Then s lines are given. These are submits’ descriptions. Description of each submit consists of the problem‘s letter and the judge verdict separated by space. The letter of the problem is the title Latin letter and all problems are numbered by first p letters of English alphabet. The judge verdict can be one of the following: Accepted, Wrong Answer, Runtime Error, Time Limit Exceeded, Memory Limit Exceeded, Compilation Error.
Output
Print the table, which consists of n+1 lines and 3 columns. Each line (except the first) gives the description of the contest. The first column gives the name of the contest, the second column gives the date of the contest (exactly as it was given in the input), the third column gives the description of the problems. Every description of problems is the line of 13 characters, where the i-th character correlate with the i-th problem. If the problem got verdict Accepted at least one time, this character is ’o’. If the problem was submitted at least once but wasn’t accepted, the character is ’x’. If the problem was just given at the contest but wasn’t submitted, the character is ’.’. Otherwise, the character is ’ ’ (space). Contests in the table must be placed in the same order as in input.
Column with the name of the contest consists of 30 symbols (shorter names must be extended by spaces added to the right to make this length). Columns with the date and description of problems consist of 8 and 13 characters accordingly.
The first line of the table gives the names of columns. The boundaries of the table are formatted by ’|’, ’-’ и ’+’ symbols. To get detailed understanding of the output format you can look at the example.
Sample
input | output |
2Codeforces Gamma Round 51229.02.165 4A AcceptedB AcceptedC AcceptedE AcceptedURKOP17.10.1512 11A AcceptedB Wrong AnswerB Time Limit ExceededJ AcceptedB AcceptedJ Time Limit ExceededJ AcceptedF AcceptedE Runtime ErrorH AcceptedE Runtime Error | +------------------------------+--------+-------------+|Contest name |Date |ABCDEFGHIJKLM|+------------------------------+--------+-------------+|Codeforces Gamma Round 512 |29.02.16|ooo.o |+------------------------------+--------+-------------+|URKOP |17.10.15|oo..xo.o.o.. |+------------------------------+--------+-------------+ |
Problem Author: Kirill Borozdin (prepared by Kirill Borozdin, Alexey Danilyuk)
Problem Source: Ural Regional School Programming Contest 2015
Tags: none ( hide tags for unsolved problems
Difficulty: 148
Printable version
Submit solution
Discussion (1)
All submissions (1735)
All accepted submissions (590)
Solutions rating (431)