How to make the strings upside down
来源:互联网 发布:mvc php路由文件加载 编辑:程序博客网 时间:2024/06/05 19:03
Problem description The children often play a game like this.When one child say some words like "abc",the other must say "cba" as soon as possible.When we take them in the computer,it will give the correct answer quickly. But in China,there is a big problem when we play the game.The ideogram covers different bits from English letter.That is to say, we will consider that how to give a new string which is read from back to front.Meanwhile,don't change any ideograms.
Input Standard input will contain multiple test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow, each string is on a separate line and consists of at most 1,000 letters or ideograms.
Output The output will contain a new string which is read from back to front.
Sample Input
【Learn】:
The end.
Input Standard input will contain multiple test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow, each string is on a separate line and consists of at most 1,000 letters or ideograms.
Output The output will contain a new string which is read from back to front.
Sample Input
1Acm 程序设计大赛
Sample Output赛大计设序程 mcA
【注】
这个题目的关键当然在于输出汉字,倒序输出没有问题。
利用汉字编码为负数的特点判断为汉字的倒序连续输出两个字符即可。
#include <cstring>#include <cstdio>int main(){char s[2048];int n;scanf("%d\n", &n);while (n--) { gets(s); int m = strlen(s); for (int i = m - 1; i >= 0; i--) { if(s[i] < 0 && s[i-1] < 0) { printf("%c%c",s[i-1],s[i]); i-=1; } else printf("%c",s[i]); } printf("\n"); }return 0;}
【Learn】:
1.汉字输出%c%c且编码为负
2.cout 不能与printf 混用,否则提交时会出现PE
3.strrev函数可以用于一般的倒序
4.scanf("%d\n",&n);与scanf("%d",&n);getchar;空格与换行
//感谢LuoXun老师!
//【函数示例】#include<stdio.h>#include<string.h>int main(){ char str1[] = "abcxyz";// 若改为 char *str1 = "abcxyz";,程序在运行时会崩溃 char *ret1 = strrev(str1); printf("The origin string of str1 is: %s\n", str1); printf("The reverse string of str1 is: %s\n", ret1); return 0;}//运行结果://The origin string of str1 is: zyxcba//The reverse string of str1 is: zyxcba
The end.
0 1
- How to make the strings upside down
- How to make the sprite image ?
- Down to the TLP: How PCI express devices talk
- how to catch the NIC interrupt(up/down) event?
- Binary Tree Upside Down
- Binary Tree Upside Down
- Binary Tree Upside Down
- Binary Tree Upside Down
- Binary Tree Upside Down
- Binary Tree Upside Down
- Binary Tree Upside Down
- how to `make` the src code of APUE book
- AxWindowsMediaPlayer how to make the Tracker disappear when playing
- [English Homwork] How to make money on the Internet
- ASP.NET MVC - how to make users confirm the delete
- how to make the XVim still available on xcode7
- The Grammer of Graphics 读书笔记 - How To Make a Pie
- How to make 9-patch image downloaded from the Network
- replace防止数据表中重复数据插入
- JavaWeb spring 常见的缺包异常
- java实现Excel导入数据库,数据库中的数据导入到Excel表格中
- 边学NodeMcu边学Lua--GPIO,PWM操作
- STL-空间配置器(allocator)
- How to make the strings upside down
- linux(ubuntu)编译linux内核提示"mkimage" command not found
- Tomcat的性能与最大并发数
- R语言(转载)之par()函数
- Linux驱动手动绑定和解绑定
- HashMap多线程下发生死循环的原因
- A1106. Lowest Price in Supply Chain (25)
- springboot data rest 4
- 加密ASP为DLL的详细步骤给点RMB不多是个心意尊重脑力劳动者的付出