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. LeetCode之461. Hamming Distance

    ------------------------------------------------------------------ AC代码: public class Solution { pub ...

  2. Android Studio 关联源码问题

    Android Studio 点击某个类查看源码有时候会出现如下情况  这种情况并不是每个项目都会出现这种情况,那是因为项目的编译版本不同,有的关联了Sources中的源码,而有的没有. 下面说一下具 ...

  3. C#中的隐式类型var——详细示例解析

    从 Visual C# 3.0 开始,在方法范围中声明的变量可以具有隐式类型var.隐式类型可以替代任何类型,它的具体类型由编译器根据上下文推断而出. 下面就让我来总结下隐式类型的一些特点: 1.va ...

  4. mysql 字符串 日期互转

    一.字符串转日期 下面将讲述如何在MySQL中把一个字符串转换成日期: 背景:rq字段信息为:20100901 1.无需转换的: SELECT * FROM tairlist_day WHERE rq ...

  5. iphone 尺寸and字体

    iPhone的APP界面一般由四个元素组成,分别是:状态栏.导航栏.主菜单栏以及中间的内容区域 这里取用 640×960 的尺寸设计,那我们就说说在这个尺寸下这些元素的尺寸: 状态栏:就是我们经常说的 ...

  6. 从外部浏览开启app

    先描述一下需求:从浏览器中点击某个按钮,如果手机上装有相应的app,则直接开启app,并且到相对的页面.如果没有装该app,则会到相应的下载app的界面. 我这里主要用的是第三方的东西,就是魔窗中的m ...

  7. MongoVUE1.6.9破解启动提示System.ArgumentException: 字体“Courier New”不支持样式“Regular”

    用MongoVUE,发现报错,报错信息如下: System.ArgumentException: 字体"Courier New"不支持样式"Regular". ...

  8. 修改socket为keepAlive

    参考文章:http://blog.csdn.net/ctthuangcheng/article/details/8596818 [root@mdw- gpadmin]# vi /etc/sysctl. ...

  9. HTML5 学习笔记(三)——本地存储

    目录 一.HTML4客户端存储 1.1.提交表单发送到服务器的信息 1.2.客户端本地存储概要 二.localStorage 2.1.添加 2.2.取值 2.3.修改 2.4.删除 2.5.跨页面与跨 ...

  10. Struts相关

    使用Struts2流程: 1.导入Struts2类包 2.在Web源代码文件夹中,创建名为struts.xml的配置文件.在其中定义Action对象,其关键代码如下: struts.xml: < ...