2014
01-05

# GPA

Each course grade is one of the following five letters: A, B, C, D, and F. (Note that there is no grade E.) The grade A indicates superior achievement , whereas F stands for failure. In order to calculate the GPA, the letter grades A, B, C, D, and F are assigned the following grade points, respectively: 4, 3, 2, 1, and 0.

The input file will contain data for one or more test cases, one test case per line. On each line there will be one or more upper case letters, separated by blank spaces.

The input file will contain data for one or more test cases, one test case per line. On each line there will be one or more upper case letters, separated by blank spaces.

A B C D F
B F F C C A
D C E F

2.00
1.83
Unknown letter grade in input

#include <iostream>
#include <cmath>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
freopen("in1.txt","r", stdin);
string s;
int len;
double sum;
int count;
while (getline(cin, s))
{
len = s.length();
sum = 0;
count = 0;
bool flag = false;
for (int i = 0; i < len; i++)
{
if (s[i] == ' ')
continue;
if (s[i] == 'A')
{
sum += 4;
count++;
}
else
if (s[i] == 'B')
{
sum += 3;
count++;
}
else
if (s[i] == 'C')
{
sum += 2;
count++;
}
else
if (s[i] == 'D')
{
sum += 1;
count++;
}
else
if (s[i] == 'F')
{
count++;
}
else
{
flag = true;
break;
}
}
if (!flag)
{
cout<<(int)sum/count;
cout<<".";
double tmp = sum/(double)count;
cout<<(int)(tmp*10.0)%10;
cout<<(int)(tmp*100.0)%10;
cout<<endl;
}
}
}

1. for(int i=1; i<=m; i++){
for(int j=1; j<=n; j++){
dp = dp [j-1] + 1;
if(s1.charAt(i-1) == s3.charAt(i+j-1))
dp = dp[i-1] + 1;
if(s2.charAt(j-1) == s3.charAt(i+j-1))
dp = Math.max(dp [j - 1] + 1, dp );
}
}
这里的代码似乎有点问题？ dp(i)(j) = dp(i)(j-1) + 1;这个例子System.out.println(ils.isInterleave("aa","dbbca", "aadbbcb"));返回的应该是false