B1024. 科學計數法 (20)
Description:
科學計數法是科學家用來表示很大或很小的數字的一種方便的方法,其滿足正則表達式[+-][1-9]"."[0-9]+E[+-][0-9]+,即數字的整數部分只有1位,小數部分至少有1位,該數字及其指數部分的正負號即使對正數也必定明確給出。
現以科學計數法的格式給出實數A,請編寫程序按普通數字表示法輸出A,並保證所有有效位都被保留。
Input:
每個輸入包含1個測試用例,即一個以科學計數法表示的實數A。該數字的存儲長度不超過9999字節,且其指數的絕對值不超過9999。
Output:
對每個測試用例,在一行中按普通數字表示法輸出A,並保證所有有效位都被保留,包括末尾的0。
Sample Input1:
+1.23400E-03
Sample Output1:
0.00123400
Sample Input2:
-1.2E+10
Sample Output2:
-12000000000
1 #include <cstdio> 2 #include <cstring> 3 4 int main() 5 { 6 char str[10010]; 7 gets(str); 8 9 int len = strlen(str); 10 if(str[0] == '-') printf("-"); 11 int pos = 0; 12 while(str[pos] != 'E') ++pos; 13 int exp = 0; 14 for(int i=pos+2; i<len; ++i) exp = exp*10+(str[i]-'0'); 15 if(exp == 0) { 16 for(int i=1; i<pos; ++i) 17 printf("%c", str[i]); 18 } 19 if(str[pos+1] == '-') { 20 printf("0."); 21 for(int i=0; i<exp-1; ++i) printf("0"); 22 printf("%c", str[1]); 23 for(int i=3; i<pos; ++i) printf("%c", str[i]); 24 } else { 25 for(int i=1; i<pos; ++i) { 26 if(str[i] == '.') continue; 27 printf("%c", str[i]); 28 if(i==exp+2 && pos-3!=exp) printf("."); 29 } 30 for(int i=0; i<exp-(pos-3); ++i) printf("0"); 31 } 32 33 return 0; 34 }
A1073. Scientific Notation (20)
Description:
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:
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:
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 Input1:
+1.23400E-03
Sample Output1:
0.00123400
Sample Input2:
-1.2E+10
Sample Output2:
-12000000000
1 #include <cstdio> 2 #include <cstring> 3 4 int main() 5 { 6 char str[10010]; 7 gets(str); 8 9 int len = strlen(str); 10 if(str[0] == '-') { 11 printf("-"); 12 } 13 int pos = 0; 14 while(str[pos] != 'E') { 15 ++pos; 16 } 17 int exp = 0; 18 for(int i=pos+2; i<len; ++i) { 19 exp = exp*10+str[i]-'0'; 20 } 21 if(exp == 0) { 22 for(int i=1; i<pos; ++i) { 23 printf("%c", str[i]); 24 } 25 } 26 if(str[pos+1] == '-') { 27 printf("0."); 28 for(int i=0; i<exp-1; ++i) { 29 printf("0"); 30 } 31 printf("%c", str[1]); 32 for(int i=3; i<pos; ++i) { 33 printf("%c", str[i]); 34 } 35 } else { 36 for(int i=1; i<pos; ++i) { 37 if(str[i] == '.') { 38 continue; 39 } 40 printf("%c", str[i]); 41 if(i==exp+2 && pos-3!=exp) { 42 printf("."); 43 } 44 } 45 for(int i=0; i<exp-(pos-3); ++i) { 46 printf("0"); 47 } 48 } 49 50 return 0; 51 }
A1001. A+B Format (20)
Description:
Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).
Input:
Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.
Output:
For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.
Sample Input:
-1000000 9
Sample Output:
-999,991
1 #include <cstdio> 2 3 int main() 4 { 5 int a, b, num[10] = {0}; 6 scanf("%d%d", &a, &b); 7 8 int len = 0, sum = a+b; 9 if(sum < 0) { 10 printf("-"); 11 sum = -sum; 12 } 13 do { 14 num[len++] = sum%10; 15 sum /= 10; 16 } while(sum != 0); 17 for(int k=len-1; k>=0; --k) { 18 printf("%d", num[k]); 19 if(k>0 && k%3==0) { 20 printf(","); 21 } 22 } 23 24 return 0; 25 }
A1005. Spell It Right (20)
Description:
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.
Input:
Each input file contains one test case. Each case occupies one line which contains an N (<= 10100).
Output:
For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.
Sample Input:
12345
Sample Output:
one five
1 #include <cstdio> 2 #include <cstring> 3 4 char s[111], num[10][10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; 5 int digit[10]; 6 7 int main() 8 { 9 gets(s); 10 11 int sum = 0, numLen = 0, len = strlen(s); 12 for(int i=0; i<len; ++i) sum += (s[i]-'0'); 13 do { 14 digit[numLen++] = sum%10; 15 sum /= 10; 16 } while(sum != 0); 17 18 for(int i=numLen-1; i>=0; --i) { 19 printf("%s", num[digit[i]]); 20 if(i != 0) printf(" "); 21 } 22 23 return 0; 24 }
A1035. Password (20)
Description:
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L in lowercase), or 0 (zero) from O (o in uppercase). One solution is to replace 1 (one) by @, 0 (zero) by %, l by L, and O by o. Now it is your job to write a program to check the accounts generated by the judge, and to help the juge modify the confusing passwords.
Input:
Each input file contains one test case. Each case contains a positive integer N (<= 1000), followed by N lines of accounts. Each account consists of a user name and a password, both are strings of no more than 10 characters with no space.
Output:
For each test case, first print the number M of accounts that have been modified, then print in the following M lines the modified accounts info, that is, the user names and the corresponding modified passwords. The accounts must be printed in the same order as they are read in. If no account is modified, print in one line "There are N accounts and no account is modified" where N is the total number of accounts. However, if N is one, you must print "There is 1 account and no account is modified" instead.
Sample Input1:
3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa
Sample Output1:
2
Team000002 RLsp%dfa
Team000001 R@spodfa
Sample Input2:
1
team110 abcdefg332
Sample Output2:
There is 1 account and no account is modified
Sample Input3:
2
team110 abcdefg222
team220 abcdefg333
Sample Output3:
There are 2 accounts and no account is modified
1 #include <cstdio> 2 #include <cstring> 3 4 struct node { 5 char name[20], password[20]; 6 bool ischange; 7 } T[1005]; 8 9 void crypt(node &t, int &cnt) { 10 int len = strlen(t.password); 11 for(int i=0; i<len; ++i) { 12 if(t.password[i] == '1') { 13 t.password[i] = '@', t.ischange = true; 14 } else if(t.password[i] == '0') { 15 t.password[i] = '%', t.ischange = true; 16 } else if(t.password[i] == 'l') { 17 t.password[i] = 'L', t.ischange = true; 18 } else if(t.password[i] == 'O') { 19 t.password[i] = 'o', t.ischange = true; 20 } 21 } 22 if(t.ischange) ++cnt; 23 } 24 25 int main() 26 { 27 int n, cnt = 0; 28 scanf("%d", &n); 29 for(int i=0; i<n; ++i) 30 scanf("%s%s", T[i].name, T[i].password); 31 32 for(int i=0; i<n; ++i) crypt(T[i], cnt); 33 if(cnt == 0) { 34 if(n == 1) printf("There is %d account and no account is modified\n", n); 35 else printf("There are %d accounts and no account is modified\n", n); 36 } else { 37 printf("%d\n", cnt); 38 for(int i=0; i<n; ++i) { 39 if(T[i].ischange) printf("%s %s\n", T[i].name, T[i].password); 40 } 41 } 42 43 return 0; 44 }