串“abcd”每个字符都向右移位,最右的则移动到第一个字符的位置,就变为“dabc”,这称为对串进行位移=1的轮换。同理,“abcd”变为“cdab”则称为位移=2的轮换。要求从键盘读入一个字符串str(约定字符串中字符数≤80字节,字符串中可以有空格)和需要位移的值n(n>str的长度时,循环位移),输出对该字符串进行位移=n的轮换结果。
中的abcdefg、3和图2中的abcdefg、11是从键盘输入的内容。
Please input the string: abcdefg
Please input n: 3
The result is: efgabcd
图1 程序运行效果示例(n<str长度时)
Please input the string: abcdefg
Please input n: 11
The result is: defgabc
图1 程序运行效果示例(n>str长度时)
中的abcdefg、3和图2中的abcdefg、11是从键盘输入的内容。
Please input the string: abcdefg
Please input n: 3
The result is: efgabcd
图1 程序运行效果示例(n<str长度时)
Please input the string: abcdefg
Please input n: 11
The result is: defgabc
图1 程序运行效果示例(n>str长度时)