Official

A - Plural Form Editorial by evima


If you have just begun studying programming and don’t know what to start with, first try Problem A “Welcome to AtCoder” in the “practicecontest” (https://atcoder.jp/contests/practice/). There you can find the sample code for each language.

In this problem, we need to perform a conditional branch depending on “the last letter of the input string.” Check how can we retrieve “the \(i\)-th letter of a string” in each language. (In most language, you can use an array-like notation \(S[i]\) to obtain it)

Sample Code (Python)

S = input()

if S[-1] == "s":
	S += "es"
else:
	S += "s"

print(S)

Sample Code (C++)

#include <iostream>
using namespace std;

int main(){
	string S;
	cin >> S;
	int len=S.length();
	
	if(S[len-1]=='s'){
		S += "es";
	}else{
		S += "s";
	}

	cout << S;
}

Sample Code (C)

#include<stdio.h>
#include<string.h>

int main(){
	char S[1010];
	scanf("%s",S);
	int len=strlen(S);
	
	if(S[len-1]=='s'){
		printf("%ses",S);
	}else{
		printf("%ss",S);
	}
}

posted:
last update: