[YTU]_1096( 字符逆序)
生活随笔
收集整理的這篇文章主要介紹了
[YTU]_1096( 字符逆序)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
將一個(gè)字符串str的內(nèi)容顛倒過(guò)來(lái),并輸出。str的長(zhǎng)度不超過(guò)100個(gè)字符。
Input
輸入包括一行。第一行輸入的字符串。
Output
輸出轉(zhuǎn)換好的逆序字符串。
Sample Input
I am a studentSample Output
tneduts a ma I
#include <iostream> #include <cstring> using namespace std; int main() { char ch[101],temp; int i,length; gets(ch); length=strlen(ch); for(i=0;i<length/2;i++) { temp=ch[i]; ch[i]=ch[length-1-i]; ch[length-1-i]=temp; } for(i=0;i<length;i++) cout<<ch[i]; cout<<endl; return 0; }
#include <iostream> #include <cstring> using namespace std; int main() { char ch[101],temp; int i,length; gets(ch); length=strlen(ch); for(i=0;i<length/2;i++) { temp=ch[i]; ch[i]=ch[length-1-i]; ch[length-1-i]=temp; } for(i=0;i<length;i++) cout<<ch[i]; cout<<endl; return 0; }
總結(jié)
以上是生活随笔為你收集整理的[YTU]_1096( 字符逆序)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: [YTU]_2443( C++习题 复数
- 下一篇: [YTU]_1985( C语言实验——保