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/字符串处理习题集(二)的更多相关文章

  1. PAT/字符串处理习题集(一)

    B1006. 换个格式输出整数 (15) Description: 让我们用字母B来表示"百".字母S表示"十",用"12...n"来表示个 ...

  2. Java-J2SE学习笔记-字符串转化为二维数组

    1.字符串转化为二维Double数组 2.代码: package Test; public class TestDouble { public static void main(String[] ar ...

  3. PAT 字符串-02 删除字符串中的子串

    /* 2 *PAT 字符串-02 删除字符串中的子串 3 *2015-08-09 4 作者:flx413 5 */ #include<stdio.h> #include<string ...

  4. CF习题集二

    CF习题集二 一.CF507E Breaking Good 题目描述 \(Breaking Good\)这个游戏对于有经验的玩家来说也有一定的难度. 游戏的主角小明希望加入一个叫斧头帮的犯罪团伙.这个 ...

  5. PAT/简单模拟习题集(二)

    B1018. 锤子剪刀布 (20) Discription: 大家应该都会玩"锤子剪刀布"的游戏:两人同时给出手势,胜负规则如图所示: 现给出两人的交锋记录,请统计双方的胜.平.负 ...

  6. MATLAB常用字符串函数之二

    1,lower和upper lower: 将包含的全部字母转换为小写. upper: 将包含的全部字母转化为大写. 实例一: >>str='Sophia is a good girl.'; ...

  7. PAT/查找元素习题集

    B1004. 成绩排名 (20) Description: 读入n名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. Input: 每个测试输入包含1个测试用例,格式为: 第1行: ...

  8. Python字符串常用方法(二)

    二.字符串的操作常用方法 字符串的替换.删除.截取.复制.连接.比较.查找.分割等 1. string. lower() :转小写 2. string. upper() :转大写 3. string. ...

  9. pat 团体赛练习题集 L2-008. 最长对称子串

    对给定的字符串,本题要求你输出最长对称子串的长度.例如,给定"Is PAT&TAP symmetric?",最长对称子串为"s PAT&TAP s&quo ...

随机推荐

  1. PHP反射API

    近期忙着写项目,没有学习什么特别新的东西,所以好长时间没有更新博客.我们的项目用的是lumen,是基于laravel的一个轻量级框架,我看到里面用到了一些反射API机制来帮助动态加载需要的类.判断方法 ...

  2. 用winform程序来了解委托和事件

    一.浅谈委托 如果有个过winform 和webform 程序开发的小伙伴一定有个这样的感觉吧,点击Button直接就执行了那个方法,到此他是怎么实现了的呢,大家有考虑过没有? 回到正题,什么是委托呢 ...

  3. SQL注入以及如何防止和索引

    SQL注入产生的原因:程序开发过程中不注意规范书写sql语句和对特殊字符进行过滤,导致客户端可以通过全局变量POST和GET提交一些sql语句正常执行. 防止SQL注入: 1.开启配置文件中的magi ...

  4. Optimal Flexible Architecture(最优灵活架构)

    来自:Oracle® Database Installation Guide 12_c_ Release 1 (12.1) for Linux Oracle base目录命名规范: /pm/s/u 例 ...

  5. 解决Trauncate table没权限

    错误信息Cannot find the object "TableName" because it does not exist or you do not have permis ...

  6. #英文#品读中国城市个性——秦汉雄风&和祖先在一起

    妨碍 interfere with 仇恨 hatred ​坍塌 collapse 专制君主 autocratic dictator 排除异己 suppress opposition 被逼到绝望边缘 b ...

  7. 阿里云linux ecs服务器配置apache+php环境

    我们需要安装的软件有apache,php和MySQL. 首先关闭SELINUX(SELINUX是一个安全子系统,它能控制程序只能访问特定文件.如果不关闭,你可能访问文件受限): vi /etc/sel ...

  8. 活动助手Beta用户试用报告

    用户试用报告 1.面向参与者用户 1.1 日常参加各类学习(水综测)活动中,有没有遇到以下问题: (1) 信息来源混乱,不知道靠不靠谱 (2) 每次报名都要重新填写自己的学号手机号,有时候填错了就没综 ...

  9. 构建高性能的MYSQL数据库系统

    实验环境: DB1:172.16.1.100 DB2:172.16.1.101 VRRIP:172.16.1.99 步骤: yum -y install mysql 1.修改DB1的mysql配置文件 ...

  10. Gym 100646 F Tanks a Lot RMQ

    Problem F: Tanks a Lot Imagine you have a car with a very large gas tank - large enough to hold what ...