天梯赛——Left-pad(字符串输入getline())

题目链接:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
    int n;
    char c;
    string s;
    scanf("%d %c",&n,&c);
    getchar();
    //string s;
   getline(cin,s);
    //gets(s);
    int len=s.length();
    if(n>=len)
    {
        for(int i=0;i<(n-len);i++)
        {
            cout<<c;
        }
        cout<<s;
    }
    else
    {
        int i=len-n;
        for(;i<=len-1;i++)
        {
            printf("%c",s[i]);
        }
    }
    return 0;
}

这种题目错好多次了,还没有记住!!!

猜你喜欢

转载自blog.csdn.net/qq_42232118/article/details/81750399