[YTU]_1096( 字符逆序)
生活随笔
收集整理的這篇文章主要介紹了
[YTU]_1096( 字符逆序)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
將一個字符串str的內容顛倒過來,并輸出。str的長度不超過100個字符。
Input
輸入包括一行。第一行輸入的字符串。
Output
輸出轉換好的逆序字符串。
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; }
總結
以上是生活随笔為你收集整理的[YTU]_1096( 字符逆序)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [YTU]_2443( C++习题 复数
- 下一篇: [YTU]_1985( C语言实验——保