https://www.codechef.com/problems/FLOW004
In C++.................
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
string s;
while(t--){
cin>>s;
int l=s.size();
cout<<(s[0]-'0')+(s[l-1]-'0')<<endl;
}
return 0;
}
In C#............
using System;
public class Program
{
public static int Counting(string s)
{
int l = s.Length;
int f = (s[0])-'0';
int la = (s[l - 1])-'0';
return la+f;
}
public static void Main()
{
int T = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < T;i++ )
{
string s = Console.ReadLine();
Console.WriteLine(Counting(s));
}
Console.ReadKey();
}
}
In C++.................
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
string s;
while(t--){
cin>>s;
int l=s.size();
cout<<(s[0]-'0')+(s[l-1]-'0')<<endl;
}
return 0;
}
In C#............
using System;
public class Program
{
public static int Counting(string s)
{
int l = s.Length;
int f = (s[0])-'0';
int la = (s[l - 1])-'0';
return la+f;
}
public static void Main()
{
int T = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < T;i++ )
{
string s = Console.ReadLine();
Console.WriteLine(Counting(s));
}
Console.ReadKey();
}
}
No comments:
Post a Comment