7-31 字符串循环左移(20 分)

7-31

输入一个字符串和一个非负整数N,要求将字符串循环左移N次。

输入格式:

输入在第1行中给出一个不超过100个字符长度的、以回车结束的非空字符串;第2行给出非负整数N。

输出格式:

在一行中输出循环左移N次后的字符串。

输入样例:

Hello World!
2

输出样例:

llo World!He

AC代码

#include<stdio.h>
#define max 105
int main(){
    char s;//指单独一个字符
    char t[max];//创建一个字符数组
    int i = 0, count = 0, flag = 0;
    while ((s=getchar()) != ‘\n‘) {//getchar每次从标准输入读入一个字符 ,标准输入会有‘\n‘???
        t[i++] = s;
        count++;
    }
    int N;
    scanf("%d",&N);
    if(N > count) {
        N %= count;
    } //这里有个测试点
    for(int i=N;i<count;i++){
        printf("%c",t[i]);
    }
    for(int i=0;i<N;i++){
        printf("%c",t[i]);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/lingr7/p/9275963.html

时间: 2024-08-01 09:32:49

7-31 字符串循环左移(20 分)的相关文章

5-31 字符串循环左移 (20分)

输入一个字符串和一个非负整数N,要求将字符串循环左移N次. 输入格式: 输入在第1行中给出一个不超过100个字符长度的.以回车结束的非空字符串:第2行给出非负整数N. 输出格式: 在一行中输出循环左移N次后的字符串. 输入样例: Hello World! 2 输出样例: llo World!He #include <stdio.h> #include <stdlib.h> int main() { int N; int length = 0; char a[100],b[100];

10-4. 字符串循环左移(20)

输入一个字符串和一个非负整数N,要求将字符串循环左移N次. 输入格式: 输入在第1行中给出一个不超过100个字符长度的.以回车结束的非空字符串:第2行给出非负整数N. 输出格式: 在一行中输出循环左移N次后的字符串. 输入样例: Hello World! 2 输出样例: llo World!He 1 #include <stdio.h> 2 #include <string.h> 3 4 int main() 5 { 6 char str[101]; 7 int t; 8 gets

字符串-05. 字符串循环左移(20)

输入一个字符串和一个非负整数N,要求将字符串循环左移N次. 输入格式: 输入在第1行中给出一个不超过100个字符长度的.以回车结束的非空字符串:第2行给出非负整数N. 输出格式: 在一行中输出循环左移N次后的字符串. 输入样例: Hello World! 2 输出样例: llo World!He import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(St

*字符串-05. 字符串循环左移

1 /* 2 * Main.c 3 * D5-字符串-05. 字符串循环左移 4 * Created on: 2014年8月19日 5 * Author: Boomkeeper 6 ********部分通过******* 7 */ 8 9 #include <stdio.h> 10 11 int main(void){ 12 13 char str[100]={0}; 14 int N=0; 15 int endIndex=99;//字符串的结尾标识符 16 17 gets(str); 18

字符串循环左移

输入一个字符串和一个非负整数N,要求将字符串循环左移N次. 输入格式: 输入在第1行中给出一个不超过100个字符长度的.以回车结束的非空字符串:第2行给出非负整数N. 输出格式: 在一行中输出循环左移N次后的字符串. 输入样例: Hello World! 2 输出样例: llo World!He #include<stdio.h>#include<string.h> int main(){ char s[101],s2[101];  int n;  gets(s);  char *

习题3.12 另类循环队列 (20分)

理解 理解: 实现循环队列 队首Q->Front=(Q->Front+1)%Q->MaxSize; 队尾Q->Rear=(Q->Front+Q->Count)%Q->MaxSize; 删除操作:移动队首,计数器Count--: 插入操作:先执行计数器Count++,在执行向后移动队尾(这里也可以先移动队尾,后执行Count++,知识删除操作取出数的下标要变化): 注意:队首默认为0: bool AddQ(Queue Q,ElementType X) { if(Q-

PTA乙级(1078 字符串压缩与解压 (20分))

1078 字符串压缩与解压 (20分) https://pintia.cn/problem-sets/994805260223102976/problems/994805262018265088 1 #include <cstdio> 2 #include <cstring> 3 #include <string> 4 #include <iostream> 5 #include <algorithm> 6 using namespace std

B1008 数组元素循环右移问题 (20分)

B1008 数组元素循环右移问题 (20分) 思路 1 2 3 4 5 6 5 6 1 2 3 4 6个数,循环右移2位. 也可以理解为 先翻转 6 5 4 3 2 1 然后再两部分,分别翻转 5 6 1 2 3 4 AC代码 #include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { int n, m; cin >> n >&

1077 Kuchiguse (20 分)求字符串最长相同后缀

1077 Kuchiguse (20 分) 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 ofte