PAT/字符串处理习题集(二)
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
#include <cstdio>
#include <cstring> int main()
{
char str[];
gets(str); int len = strlen(str);
if(str[] == '-') printf("-");
int pos = ;
while(str[pos] != 'E') ++pos;
int exp = ;
for(int i=pos+; i<len; ++i) exp = exp*+(str[i]-'');
if(exp == ) {
for(int i=; i<pos; ++i)
printf("%c", str[i]);
}
if(str[pos+] == '-') {
printf("0.");
for(int i=; i<exp-; ++i) printf("");
printf("%c", str[]);
for(int i=; i<pos; ++i) printf("%c", str[i]);
} else {
for(int i=; i<pos; ++i) {
if(str[i] == '.') continue;
printf("%c", str[i]);
if(i==exp+ && pos-!=exp) printf(".");
}
for(int i=; i<exp-(pos-); ++i) printf("");
} return ;
}
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
#include <cstdio>
#include <cstring> int main()
{
char str[];
gets(str); int len = strlen(str);
if(str[] == '-') {
printf("-");
}
int pos = ;
while(str[pos] != 'E') {
++pos;
}
int exp = ;
for(int i=pos+; i<len; ++i) {
exp = exp*+str[i]-'';
}
if(exp == ) {
for(int i=; i<pos; ++i) {
printf("%c", str[i]);
}
}
if(str[pos+] == '-') {
printf("0.");
for(int i=; i<exp-; ++i) {
printf("");
}
printf("%c", str[]);
for(int i=; i<pos; ++i) {
printf("%c", str[i]);
}
} else {
for(int i=; i<pos; ++i) {
if(str[i] == '.') {
continue;
}
printf("%c", str[i]);
if(i==exp+ && pos-!=exp) {
printf(".");
}
}
for(int i=; i<exp-(pos-); ++i) {
printf("");
}
} return ;
}
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
#include <cstdio> int main()
{
int a, b, num[] = {};
scanf("%d%d", &a, &b); int len = , sum = a+b;
if(sum < ) {
printf("-");
sum = -sum;
}
do {
num[len++] = sum%;
sum /= ;
} while(sum != );
for(int k=len-; k>=; --k) {
printf("%d", num[k]);
if(k> && k%==) {
printf(",");
}
} return ;
}
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
#include <cstdio>
#include <cstring> char s[], num[][] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
int digit[]; int main()
{
gets(s); int sum = , numLen = , len = strlen(s);
for(int i=; i<len; ++i) sum += (s[i]-'');
do {
digit[numLen++] = sum%;
sum /= ;
} while(sum != ); for(int i=numLen-; i>=; --i) {
printf("%s", num[digit[i]]);
if(i != ) printf(" ");
} return ;
}
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
#include <cstdio>
#include <cstring> struct node {
char name[], password[];
bool ischange;
} T[]; void crypt(node &t, int &cnt) {
int len = strlen(t.password);
for(int i=; i<len; ++i) {
if(t.password[i] == '') {
t.password[i] = '@', t.ischange = true;
} else if(t.password[i] == '') {
t.password[i] = '%', t.ischange = true;
} else if(t.password[i] == 'l') {
t.password[i] = 'L', t.ischange = true;
} else if(t.password[i] == 'O') {
t.password[i] = 'o', t.ischange = true;
}
}
if(t.ischange) ++cnt;
} int main()
{
int n, cnt = ;
scanf("%d", &n);
for(int i=; i<n; ++i)
scanf("%s%s", T[i].name, T[i].password); for(int i=; i<n; ++i) crypt(T[i], cnt);
if(cnt == ) {
if(n == ) printf("There is %d account and no account is modified\n", n);
else printf("There are %d accounts and no account is modified\n", n);
} else {
printf("%d\n", cnt);
for(int i=; i<n; ++i) {
if(T[i].ischange) printf("%s %s\n", T[i].name, T[i].password);
}
} return ;
}
A1077. Kuchiguse (20)
Description:
The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker's personality. Such a preference is called "Kuchiguse" and is often exaggerated artistically in Anime and Manga. For example, the artificial sentence ending particle "nyan~" is often used as a stereotype for characters with a cat-like personality:
- Itai nyan~ (It hurts, nyan~)
- Ninjin wa iyada nyan~ (I hate carrots, nyan~)
Now given a few lines spoken by the same character, can you find her Kuchiguse?
Input:
Each input file contains one test case. For each case, the first line is an integer N (2<=N<=100). Following are N file lines of 0~256 (inclusive) characters in length, each representing a character's spoken line. The spoken lines are case sensitive.
Output:
For each test case, print in one line the kuchiguse of the character, i.e., the longest common suffix of all N lines. If there is no such suffix, write "nai".
Sample Input1:
3
Itai nyan~
Ninjin wa iyadanyan~
uhhh nyan~
Sample Output1:
nyan~
Sample Input2:
3
Itai!
Ninjinnwaiyada T_T
T_T
Sample Output2:
nai
#include <cstdio>
#include <cstring> char s[][]; int main()
{ int n, minLen = , ans = ;
scanf("%d", &n);
getchar();
for(int i=; i<n; ++i) {
gets(s[i]);
int len = strlen(s[i]);
if(len < minLen) minLen = len;
for(int j=; j<len/; ++j) {
char temp = s[i][j];
s[i][j] = s[i][len-j-];
s[i][len-j-] = temp;
}
} for(int i=; i<minLen; ++i) {
char c = s[][i];
bool same = true;
for(int j=; j<n; j++) {
if(c != s[j][i]) {
same = false;
break;
}
}
if(same) ++ans;
else break;
} if(ans) for(int i=ans-; i>=; --i) printf("%c", s[][i]);
else printf("nai"); return ;
}
A1082. Read Number in Chinese (25)
Description:
Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output "Fu" first if it is negative. For example, -123456789 is read as "Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu". Note: zero ("ling") must be handled correctly according to the Chinese tradition. For example, 100800 is "yi Shi Wan ling ba Bai".
Input:
Each input file contains one test case, which gives an integer with no more than 9 digits.
Output:
For each test case, print in a line the Chinese way of reading the number. The characters are separated by a space and there must be no extra space at the end of the line.
Sample Input1:
-123456789
Sample Output1:
Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu
Sample Input1:
100800
Sample Output1:
yi Shi Wan ling ba Bai
#include <cstdio>
#include <cstring> char num[][] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"},
wei[][] = {"Shi", "Bai", "Qian", "Wan", "Yi"}; int main()
{
char str[];
gets(str); int len = strlen(str);
int left = , right = len-;
if(str[] == '-') {
printf("Fu");
++left;
}
while(left+ <= right) right -=;
while(left < len) {
bool flag = false, isPrint = false;
while(left <= right) {
if(left> && str[left]=='') flag = true;
else {
if(flag == true) {
printf(" ling");
flag = false;
}
if(left > ) printf(" ");
printf("%s", num[str[left]-'']);
isPrint = true;
if(left != right) printf(" %s", wei[right-left-]);
}
++left;
}
if(isPrint==true && right!=len-) printf(" %s", wei[(len--right)/+]);
right += ;
} return ;
}
PAT/字符串处理习题集(二)的更多相关文章
- PAT/字符串处理习题集(一)
B1006. 换个格式输出整数 (15) Description: 让我们用字母B来表示"百".字母S表示"十",用"12...n"来表示个 ...
- Java-J2SE学习笔记-字符串转化为二维数组
1.字符串转化为二维Double数组 2.代码: package Test; public class TestDouble { public static void main(String[] ar ...
- PAT 字符串-02 删除字符串中的子串
/* 2 *PAT 字符串-02 删除字符串中的子串 3 *2015-08-09 4 作者:flx413 5 */ #include<stdio.h> #include<string ...
- CF习题集二
CF习题集二 一.CF507E Breaking Good 题目描述 \(Breaking Good\)这个游戏对于有经验的玩家来说也有一定的难度. 游戏的主角小明希望加入一个叫斧头帮的犯罪团伙.这个 ...
- PAT/简单模拟习题集(二)
B1018. 锤子剪刀布 (20) Discription: 大家应该都会玩"锤子剪刀布"的游戏:两人同时给出手势,胜负规则如图所示: 现给出两人的交锋记录,请统计双方的胜.平.负 ...
- MATLAB常用字符串函数之二
1,lower和upper lower: 将包含的全部字母转换为小写. upper: 将包含的全部字母转化为大写. 实例一: >>str='Sophia is a good girl.'; ...
- PAT/查找元素习题集
B1004. 成绩排名 (20) Description: 读入n名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. Input: 每个测试输入包含1个测试用例,格式为: 第1行: ...
- Python字符串常用方法(二)
二.字符串的操作常用方法 字符串的替换.删除.截取.复制.连接.比较.查找.分割等 1. string. lower() :转小写 2. string. upper() :转大写 3. string. ...
- pat 团体赛练习题集 L2-008. 最长对称子串
对给定的字符串,本题要求你输出最长对称子串的长度.例如,给定"Is PAT&TAP symmetric?",最长对称子串为"s PAT&TAP s&quo ...
随机推荐
- hadoop2.6.4 搭建单机模式
注(要先安装jdk,最好jdk版本>=1.7) 安装jdk http://www.cnblogs.com/zhangXingSheng/p/6228432.html 给普通用户添加su ...
- brew 安装 mysql
在网上看到各种教程,都会出现ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.soc ...
- 【Java EE 学习 70 下】【数据采集系统第二天】【Action中User注入】【设计调查页面】【Action中模型赋值问题】【编辑调查】
一.Action中User注入问题 Action中可能会经常用到已经登陆的User对象,如果每次都从Session中拿会显得非常繁琐.可以想一种方法,当Action想要获取User对象的时候直接使用, ...
- 用ILSpy查看Session.SessionID的生成算法
缘由 asp.net Session在InProc模式下,容易丢失,经常需要重新登录,且不支持分布式共享. 所以在研究Redis实现原生的Session,本来想用GUID作为key存入cookie,又 ...
- Datazen安装
Datazen是被微软收购的移动端全平台的数据展现解决方案.此篇主要介绍其安装过程. 下载页面,需要留意一下的是目前还没有中文版: http://www.datazen.com/start/ 点击Do ...
- [Tool]Inno Setup创建软件安装程序。
这篇博客将介绍如何使用Inno Setup创建一个软件安装程序. Inno Setup官网:http://www.jrsoftware.org/isinfo.php. 可以下载到最新的Inno Set ...
- CSS 代码技巧与维护 ★ Mozilla Hacks – the Web developer blog
原文链接:https://hacks.mozilla.org/2016/05/css-coding-techniques/ 译文链接 :http://www.zcfy.cc/article/css-c ...
- mybatis Caused by: org.apache.ibatis.reflection.ReflectionException: Error instantiating class .. with invalid types () or values (). Cause: java.lang.NoSuchMethodException: ...<init>()
如果有带参数的构造器,编译器不会自动生成无参构造器.当查询需要返回对象时,ORM框架用反射来调用对象的无参构造函数,所以会导致此类异常 public Test(){ }
- TotoiseSVN的基本使用方法
TotoiseSVN的基本使用方法 在 项目管理实践教程一.工欲善其事,必先利其器[Basic Tools]中,我已经讲解了怎样安装TortoiseSVN.在上面的讲解中已经讲了怎么使用VisualS ...
- Xcode 8 Simulator Stop Logging too much info
按照以下内容设置即可: