标签:
1073. Scientific Notation (20)
Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [+-][1-9]"."[0-9]+E[+-][0-9]+ which means that the integer portion has exactly one digit, there is at least one digit in the fractional portion, and the number and its exponent‘s signs are always provided even when they are positive.
Now given a real number A in scientific notation, you are supposed to print A in the conventional notation while keeping all the significant figures.
Input Specification:
Each input file contains one test case. For each case, there is one line containing the real number A in scientific notation. The number is no more than 9999 bytes in length and the exponent‘s absolute value is no more than 9999.
Output Specification:
For each test case, print in one line the input number A in the conventional notation, with all the significant figures kept, including trailing zeros,
Sample Input 1:+1.23400E-03Sample Output 1:
0.00123400Sample Input 2:
-1.2E+10Sample Output 2:
-12000000000
//1073 #include <string> #include <cstring> #include <cstdio> using namespace std; char flag1; int ing; char a[10000]; char flag2; int b; char res[100000]; int main() { scanf("%c%d.", &flag1, &ing); char c; int i = 0; while((c = getchar()) != 'E') a[i++] = c; flag2 = getchar(); i = 0; scanf("%d", &b); getchar(); int j = 0; if(flag1 == '-') res[j++] = '-'; if(flag2 == '+' || b == 0) { res[j++] = ing + '0'; i = 0; while(i < b) { if(i < strlen(a)) { res[j++] = a[i++]; } else { res[j++] = '0'; i++; } } if(i < strlen(a)) { res[j++] = '.'; strcat(res, a+i); } } else { res[j++] = '0'; res[j++] = '.'; i = 1; while(i < b) { res[j++] = '0'; i++; } res[j++] = ing+'0'; strcat(res, a); } printf("%s\n", res); return 0; }
Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K = 3, then you must output 3→2→1→6→5→4; if K = 4, you must output 4→3→2→1→5→6.
Input Specification:
Each input file contains one test case. For each case, the first line contains the address of the first node, a positive N (<= 105) which is the total number of nodes, and a positive K (<=N) which is the length of the sublist to be reversed. The address of a node is a 5-digit nonnegative integer, and NULL is represented by -1.
Then N lines follow, each describes a node in the format:
Address Data Next
where Address is the position of the node, Data is an integer, and Next is the position of the next node.
Output Specification:
For each case, output the resulting ordered linked list. Each node occupies a line, and is printed in the same format as in the input.
Sample Input:00100 6 4 00000 4 99999 00100 1 12309 68237 6 -1 33218 3 00000 99999 5 68237 12309 2 33218Sample Output:
00000 4 33218 33218 3 12309 12309 2 00100 00100 1 99999 99999 5 68237 68237 6 -1
//1074 #include <cstdio> #include <algorithm> using namespace std; int addrs[100001]; struct node { int val; int next; }; node nodes[100001]; int main() { int first_addr, N, K; scanf("%d%d%d", &first_addr, &N, &K); int i; for(i = 0; i < N; i++) { int a; scanf("%d", &a); scanf("%d%d", &nodes[a].val, &nodes[a].next); } if(first_addr == -1) return 0; int next = first_addr; i = 0; while(next != -1) { addrs[i++] = next; next = nodes[next].next; } addrs[i++] = -1; N = i - 1; //需要注意,N个节点不一定都在链表里 i = 0; while(i + K <= N) { reverse(addrs+i, addrs+i+K); i += K; } for(i =0 ; i < N-1; i++) { printf("%05d %d %05d\n", addrs[i], nodes[addrs[i]].val, addrs[i+1]); } printf("%05d %d -1\n", addrs[i], nodes[addrs[i]].val); return 0; }
The ranklist of PAT is generated from the status list, which shows the scores of the submittions. This time you are supposed to generate the ranklist for PAT.
Input Specification:
Each input file contains one test case. For each case, the first line contains 3 positive integers, N (<=104), the total number of users, K (<=5), the total number of problems, and M (<=105), the total number of submittions. It is then assumed that the user id‘s are 5-digit numbers from 00001 to N, and the problem id‘s are from 1 to K. The next line contains K positive integers p[i] (i=1, ..., K), where p[i] corresponds to the full mark of the i-th problem. Then M lines follow, each gives the information of a submittion in the following format:
user_id problem_id partial_score_obtained
where partial_score_obtained is either -1 if the submittion cannot even pass the compiler, or is an integer in the range [0, p[problem_id]]. All the numbers in a line are separated by a space.
Output Specification:
For each test case, you are supposed to output the ranklist in the following format:
rank user_id total_score s[1] ... s[K]
where rank is calculated according to the total_score, and all the users with the same total_score obtain the same rank; and s[i] is the partial score obtained for the i-th problem. If a user has never submitted a solution for a problem, then "-" must be printed at the corresponding position. If a user has submitted several solutions to solve one problem, then the highest score will be counted.
The ranklist must be printed in non-decreasing order of the ranks. For those who have the same rank, users must be sorted in nonincreasing order according to the number of perfectly solved problems. And if there is still a tie, then they must be printed in increasing order of their id‘s. For those who has never submitted any solution that can pass the compiler, or has never submitted any solution, they must NOT be shown on the ranklist. It is guaranteed that at least one user can be shown on the ranklist.
Sample Input:7 4 20 20 25 25 30 00002 2 12 00007 4 17 00005 1 19 00007 2 25 00005 1 20 00002 2 2 00005 1 15 00001 1 18 00004 3 25 00002 2 25 00005 3 22 00006 4 -1 00001 2 18 00002 1 20 00004 1 15 00002 4 18 00001 3 4 00001 4 2 00005 2 -1 00004 2 0Sample Output:
1 00002 63 20 25 - 18 2 00005 42 20 0 22 - 2 00007 42 - 25 - 17 2 00001 42 18 18 4 2 5 00004 40 15 0 25 -
//1075 #include <cstdio> #include <vector> #include <algorithm> using namespace std; int mark[6]; struct user { int id; user():total(0),sub(0), per_finish(0) { for(int i = 1 ; i <= 5; i++) score[i] = -1; } int score[6]; int total; int per_finish; int sub; }; bool cmp(user a, user b) { if(a.total != b.total) return a.total > b.total; if(a.per_finish != b.per_finish) return a.per_finish > b.per_finish; if(a.total >0 && b.total>0) return a.id < b.id; if(a.sub > 0 && b.sub > 0) return a.id < b.id; if(a.sub > 0) return true; else return false; } int main() { int N, K, M; scanf("%d%d%d", &N, &K, &M); int i; vector<user> users(N+1); for(i = 1; i<=K; i++) scanf("%d", &mark[i]); for(i = 1; i <= N; i++) users[i].id = i; for(i = 0; i < M; i++) { int id, p, score; scanf("%d%d%d", &id, &p, &score); if(score >= 0) users[id].sub++; //用于标记是否有提交并通过的题目 if(users[id].score[p] == -1) users[id].score[p] = 0; if(users[id].score[p] < score) { if(score == mark[p]) users[id].per_finish++; if(users[id].score[p] <= 0) { users[id].score[p] = score; users[id].total = users[id].total + score; } else { users[id].total = users[id].total - users[id].score[p] + score; users[id].score[p] = score; } } } sort(users.begin()+1, users.end(), cmp); int j = 0; if(users[1].sub == 0) return 0; printf("1 %05d %d", users[1].id, users[1].total); for(j = 1; j <= K; j++) { if(users[1].score[j] != -1) printf(" %d", users[1].score[j]); else printf(" -"); } printf("\n"); int r = 1; for(i = 2; i <= N && users[i].sub > 0; i++) { if(users[i].total == users[i-1].total) printf("%d ", r); else { printf("%d ", i); r = i; } printf("%05d %d", users[i].id,users[i].total); for(j = 1; j <= K; j++) { if(users[i].score[j] != -1) printf(" %d", users[i].score[j]); else printf(" -"); } printf("\n"); } return 0; }
Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a user makes a post on Weibo, all his/her followers can view and forward his/her post, which can then be forwarded again by their followers. Now given a social network, you are supposed to calculate the maximum potential amount of forwards for any specific user, assuming that only L levels of indirect followers are counted.
Input Specification:
Each input file contains one test case. For each case, the first line contains 2 positive integers: N (<=1000), the number of users; and L (<=6), the number of levels of indirect followers that are counted. Hence it is assumed that all the users are numbered from 1 to N. Then N lines follow, each in the format:
M[i] user_list[i]
where M[i] (<=100) is the total number of people that user[i] follows; and user_list[i] is a list of the M[i] users that are followed by user[i]. It is guaranteed that no one can follow oneself. All the numbers are separated by a space.
Then finally a positive K is given, followed by K UserID‘s for query.
Output Specification:
For each UserID, you are supposed to print in one line the maximum potential amount of forwards this user can triger, assuming that everyone who can view the initial post will forward it once, and that only L levels of indirect followers are counted.
Sample Input:7 3 3 2 3 4 0 2 5 6 2 3 1 2 3 4 1 4 1 5 2 2 6Sample Output:
4 5
//1076 #include <cstdio> #include <vector> #include <queue> using namespace std; struct node { vector<int> next; }; int main() { int N, L, K; scanf("%d%d", &N, &L); int i; vector<node> nodes(N+1); for(i = 1; i<= N; i++) { int n; scanf("%d", &n); for(int j = 0;j < n; j++) { int a; scanf("%d", &a); nodes[a].next.push_back(i); } } scanf("%d", &K); vector<int> query(K, 0); for(i = 0 ; i< K; i++) scanf("%d", &query[i]); vector<int> res; for(i = 0; i <K; i++) { vector<int> visited(N+1, 0); queue<int> q; q.push(query[i]); visited[query[i]] = 1; int num; int sum = 0; int l = 0; while(!q.empty()) { num = q.size(); for(int j = 0; j < num; j++) { int cur = q.front(); q.pop(); for(int x = 0; x < nodes[cur].next.size(); x++) { int adj = nodes[cur].next[x]; if(visited[adj] == 0) { q.push(adj); visited[adj] = 1; sum++; } } } l++; if(l == L) { break; } } res.push_back(sum); } for(i = 0; i< res.size(); i++) printf("%d\n", res[i]); return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/lulu901130/article/details/47358035